Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4462822

Browse filesBrowse files
fix: invalid vnode._parent value
We have lots of code in hooks that checks for this being `null` when empty. This broke with `preact-render-to-string` because we did set it to `undefined` on reset here.
1 parent 5441664 commit 4462822
Copy full SHA for 4462822

File tree

3 files changed

+33
-4
lines changed
Filter options

3 files changed

+33
-4
lines changed

‎.changeset/proud-eyes-cheer.md

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'preact-render-to-string': patch
3+
---
4+
5+
Fix invalid parent pointer empty value when rendering a suspended vnode

‎src/index.js

Copy file name to clipboardExpand all lines: src/index.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ function _renderToString(
425425
return str;
426426
} finally {
427427
if (afterDiff) afterDiff(vnode);
428-
vnode[PARENT] = undefined;
428+
vnode[PARENT] = null;
429429

430430
if (ummountHook) ummountHook(vnode);
431431
}
@@ -453,7 +453,7 @@ function _renderToString(
453453
const str = renderChildren();
454454

455455
if (afterDiff) afterDiff(vnode);
456-
vnode[PARENT] = undefined;
456+
vnode[PARENT] = null;
457457

458458
if (ummountHook) ummountHook(vnode);
459459

@@ -618,7 +618,7 @@ function _renderToString(
618618
}
619619

620620
if (afterDiff) afterDiff(vnode);
621-
vnode[PARENT] = undefined;
621+
vnode[PARENT] = null;
622622
if (ummountHook) ummountHook(vnode);
623623

624624
// Emit self-closing tag for empty void elements:

‎test/compat/async.test.js

Copy file name to clipboardExpand all lines: test/compat/async.test.js
+25-1Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { renderToStringAsync } from '../../src/index.js';
22
import { h } from 'preact';
3-
import { Suspense } from 'preact/compat';
3+
import { Suspense, useId } from 'preact/compat';
44
import { expect } from 'chai';
55
import { createSuspender } from '../utils.js';
66

@@ -165,4 +165,28 @@ describe('Async renderToString', () => {
165165

166166
expect(msg).to.equal('fail');
167167
});
168+
169+
it('should support hooks', async () => {
170+
const { suspended, getResolved } = createSuspender();
171+
172+
function Suspender() {
173+
const id = useId();
174+
175+
if (!getResolved()) {
176+
throw suspended.promise;
177+
}
178+
179+
return <p>{typeof id === 'string' ? 'ok' : 'fail'}</p>;
180+
}
181+
182+
const promise = renderToStringAsync(
183+
<Suspense fallback={<div>loading...</div>}>
184+
<Suspender />
185+
</Suspense>
186+
);
187+
188+
suspended.resolve();
189+
const rendered = await promise;
190+
expect(rendered).to.equal('<p>ok</p>');
191+
});
168192
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.