diff --git a/.changeset/friendly-numbers-hang.md b/.changeset/friendly-numbers-hang.md index 764bcd8..4e8fe4b 100644 --- a/.changeset/friendly-numbers-hang.md +++ b/.changeset/friendly-numbers-hang.md @@ -2,4 +2,5 @@ 'preact-render-to-string': patch --- -Fix issue where subtree re-render for Suspense boundaries caused a circular reference in the VNode's parent +Ensure that the `_parent` is kept around across multiple suspensions and avoid circular references. +In doing so our `useId` hook should always output unique ids during renderingToString. diff --git a/package-lock.json b/package-lock.json index e4d3c80..6e40cb4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "preact-render-to-string", - "version": "6.5.11", + "version": "6.5.12", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "preact-render-to-string", - "version": "6.5.11", + "version": "6.5.12", "license": "MIT", "devDependencies": { "@babel/plugin-transform-react-jsx": "^7.12.12", @@ -14,7 +14,7 @@ "@babel/register": "^7.12.10", "@changesets/changelog-github": "^0.4.1", "@changesets/cli": "^2.18.0", - "baseline-rts": "npm:preact-render-to-string@6.5.11", + "baseline-rts": "npm:preact-render-to-string@latest", "benchmarkjs-pretty": "^2.0.1", "chai": "^4.2.0", "check-export-map": "^1.3.1", diff --git a/src/index.js b/src/index.js index 4c7fe19..ff4c774 100644 --- a/src/index.js +++ b/src/index.js @@ -443,7 +443,6 @@ function _renderToString( return EMPTY_STR; } finally { if (afterDiff) afterDiff(vnode); - vnode[PARENT] = null; if (ummountHook) ummountHook(vnode); } @@ -473,7 +472,6 @@ function _renderToString( if (afterDiff) afterDiff(vnode); // when we are dealing with suspense we can't do this... - vnode[PARENT] = null; if (options.unmount) options.unmount(vnode); @@ -688,9 +686,6 @@ function _renderToString( if (afterDiff) afterDiff(vnode); - // TODO: this was commented before - vnode[PARENT] = null; - if (ummountHook) ummountHook(vnode); // Emit self-closing tag for empty void elements: diff --git a/test/compat/render-chunked.test.js b/test/compat/render-chunked.test.js index 575e0f9..502507f 100644 --- a/test/compat/render-chunked.test.js +++ b/test/compat/render-chunked.test.js @@ -145,7 +145,48 @@ describe('renderToChunks', () => { '

id: P0-0

loading...
', '' + ]); + }); + + it('should support using multiple useId hooks inside multiple suspense boundaries', async () => { + const { Suspender, suspended } = createSuspender(); + const { Suspender: Suspender2, suspended: suspended2 } = createSuspender(); + + function ComponentWithId() { + const id = useId(); + return

id: {id}

; + } + + const result = []; + const promise = renderToChunks( +
+ + + + + + + + + + + +
, + { onWrite: (s) => result.push(s) } + ); + + suspended.resolve(); + suspended2.resolve(); + await promise; + + expect(result).to.deep.equal([ + '

id: P0-0

loading...loading...
', + '' ]); }); diff --git a/test/compat/stream-node.test.js b/test/compat/stream-node.test.js index a415d36..5783887 100644 --- a/test/compat/stream-node.test.js +++ b/test/compat/stream-node.test.js @@ -66,10 +66,10 @@ describe('renderToPipeableStream', () => { const result = await sink.promise; expect(result).to.deep.equal([ - '
loading...
', + '
loading...
', '' ]); }); diff --git a/test/compat/stream.test.js b/test/compat/stream.test.js index c3b0df3..09f6134 100644 --- a/test/compat/stream.test.js +++ b/test/compat/stream.test.js @@ -82,10 +82,10 @@ describe('renderToReadableStream', () => { const result = await sink.promise; expect(result).to.deep.equal([ - '
loading...
', + '
loading...
', '' ]); });