Repository navigation
Fix steaming issues with suspence - #5407
Open
MaxwellCohen wants to merge 17 commits into
Open
MaxwellCohen wants to merge 17 commits into
MaxwellCohen wants to merge 17 commits into
Conversation
preact-render-to-string marks the range of every Suspense boundary: `<!--$s=-->` when its content is in the HTML, `<!--$s?id-->` while the server is still to stream it, `<!--$s!-->` when the client has to render it. A boundary now hydrates that range and nothing else, and only once all of it is there. While it waits (on its chunk, or on a lazy component below it) the range stays exactly as the server sent it. When something suspends below a boundary that is hydrating, the boundary keeps the whole range and hydrates it from scratch later, instead of the suspending component keeping a guess at its own nodes. A component that is still to hydrate now moves with its DOM when a keyed list reorders. Co-Authored-By: Claude Fable 5.2
Core keeps one hook (options._claim) that lets a component take a range of the DOM it hydrates, plus the generic pieces: the streaming-aware rangeEnd, moving a suspended component's range on keyed reorders, and diffing a boundary's attributes when a parent rendered it again while it waited. Finding the range, client-rendering a $s! range and removing the markers now happen in compat, so they ship only with Suspense. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Roll back refQueue with commitQueue when a render is thrown away, so a callback ref runs once and its cleanup isn't lost - Remove the DOM of a portal mounted by a thrown-away render - Keep a parked pending boundary's opening marker for the chunk script: no copy that starts with it removes it - Unmount clears a pending range only up to a closer that is a sibling - The claim scan stops at any other boundary marker - Guard the range move in insert() against a detached cursor - Count a suspended vnode with no kept DOM as mounting for skew - One render callback per boundary however often it retries Co-Authored-By: Claude Opus 5.5
The claim scan has to step over the <!--$s--> pair renderToStringAsync writes around a component that suspended, inside its boundary's range. Co-Authored-By: Claude Opus 5.5
Revert rangeEnd to its original loop with only the pending-closer check, find the closer in componentWillUnmount with rangeEnd, inline the render callback, and drop the __w check in removeOriginal. Make the useId test check the ids it renders, not the attribute hydration keeps. Co-Authored-By: Claude Opus 5.5
Co-Authored-By: Claude Opus 5.5
📊 Tachometer Benchmark ResultsSummaryA summary of the benchmark results will show here once they finish. ResultsThe full results of your benchmarks will show here once they finish. |
This was referenced Nov 22, 2026
MaxwellCohen
marked this pull request as ready for review
November 22, 2026 17:53
rangeEnd() skips a nested range by recursing instead of counting depth, and the detached-cursor check is inlined, which gzips smaller than a helper. Co-Authored-By: Claude Opus 5.5
Co-Authored-By: Claude Opus 5.5
Core's unmount already removes a suspended component's range. Without markers, the server script finds no range for a late chunk and drops it, so Suspense no longer keeps them for the script. Co-Authored-By: Claude Opus 5.5
…cache A waiting boundary doesn't render again before its promise settles, so one promise per wait is enough. Co-Authored-By: Claude Opus 5.5
A boundary can render again while it waits (forceUpdate skips shouldComponentUpdate, e.g. on a hot reload). A new promise would replace __w and leave the first one unresolved, so the boundary never hydrated. Co-Authored-By: Claude Opus 5.5
A boundary waiting for its chunk only woke when the server's inline script called __w. Without that script (cut off, another version's, or a range it can't reach), the boundary waited forever. Resolve the wait on DOMContentLoaded too, so the range renders on the client. Co-Authored-By: Claude Opus 5.5
- _claim returns the range's closer as the cursor, not the node after it - discard the boundary's own vnode and restore its _parentDom - the marker-removal callback reuses the render's marker and fallback - check readyState by its first letter Co-Authored-By: Claude Opus 5.5
Co-Authored-By: Claude Opus 5.5
Co-Authored-By: Claude Opus 5.5
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the Preact client (core and compact) side of the suspense streaming fixes. I got these fixes from using an LLM-generated streaming harness (source). This harness found 10 categories of bugs, and the core fixes help fix 6 of them.
<preact-island>(backport fixes) preactjs/preact-render-to-string#508<template for>(move to DPU) preactjs/preact-render-to-string#509lazyFirst,multiRootClient,lazyMulti,lazyNull,realLazyNoStream,twoInOne,wrapFirstServer,lazySecond,realLazy,lazyDeep,lazyRef,wrapMidClient,serverWaterfall,lazyInDiv,textLazy,resuspend_claimhook; the boundary takes its range; a suspend goes up to the boundary; the partial render is thrown away; the server DOM stays instead of the fallback; markers are removed on commit;refQueuerollback$s=; suspensions go to the boundaryinnerPlain,outerNoRangeLazy,outerNoRange,rootBoundary,emptyPair,gateAboveNoWrap,sameTag,siblings,nest3,directNest,gateAboverangeEndfinds a range's end while a chunk is still streaming$s=opening marker; a pending range's closing marker carries its id<?start>/<?end>inside the rangehideNested,laterNested,tickProp,hideOnly,tickAttr,later$PRS()keyed,keyedComp,keyedGrow,keyedNoStreamsvgTitle,math,svgImage,svgForeign,svgserverErrorLate$s!fallback, then renders the content on the clientdata-x, or a lost template</body>splits the shell in the wrong placebodyInShell</body>at the end countsuseIdgives the wrong IDs after a render that's thrown away, so a label points at the wrong inputuseIdextNode,extNodeNested,foreignScript,foreignScriptNested$PRS()finds the template by its id, not by positionmoduleHydrate,moduleHydrateCutThis fix adds support for the server marking every boundary
I have tried to keep the changes as compact as possible
Note
Written with Claude Fable 5.2 and Claude Opus 5.5, which also wrote this description. A review pass with Grok 4.7 added the handling of markers that already shipped.
I hope this PR helps. If it doesn't help, feel free to close it or modify it in any way that helps improve Preact.