fix(hydrate): wait for waitingElements to drain before destroyWindow - #6865
Open
shoaibyazdani wants to merge 1 commit into
Open
shoaibyazdani wants to merge 1 commit into
shoaibyazdani wants to merge 1 commit into
Conversation
…tenciljs#6864) When `renderToString` fires its timeout, `finalizeHydrate` calls `destroyWindow` → `MockWindow.close` → `resetWindow`, which deletes `globalThis.fetch` and friends on the live window. Components that are still in flight — typically mid-await on `componentOnReady` or on their own `fetch` — wake up against a torn-down globalThis and start throwing. The retained render object graph (which still holds references through the component closures) prevents GC, and under concurrent `renderToString` calls the heap climbs until OOM. Apply the maintainer's preferred direction (option 2 from stenciljs#6864): drain `waitingElements` to size 0 inside `hydratedComplete` before allowing `afterHydrate` to fire (which triggers `destroyWindow` upstream in `render.ts`. A hard ceiling of `opts.timeout ?? 15000` ms caps the wait so a stuck component can't keep a render's graph alive for minutes. `hydratedComplete` becomes async; `hydratedError` fires-and-forgets with a `.catch` so the existing throw-safety stays intact. Includes a focused unit test at `src/hydrate/platform/test/drain-waiting-elements.spec.ts` covering the empty-set fast path, drain-on-emptying, and the ceiling cap. Closes stenciljs#6864
2 tasks
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.
What
When
renderToStringhits its timeout, the runner goesfinalizeHydrate→destroyWindow→MockWindow.close→resetWindow, which setsglobalThis.fetch = null(and friends) on the live window. Components that are still in flight — typically mid-await oncomponentOnReadyor on their ownfetch— wake up against the torn-down globalThis and start throwing.Approach
Apply the maintainer's preferred direction (option 2 from #6864): drain
waitingElementsto size 0 insidehydratedCompletebeforeafterHydratefires (which triggersdestroyWindowupstream). A hard ceiling ofopts.timeout ?? 15000ms caps the wait so a stuck component can't keep a render's graph alive indefinitely.hydratedCompletebecomes async;hydratedErrorfires the drain fire-and-forget with a.catchto preserve the prior throw-safety.Tests
src/hydrate/platform/test/drain-waiting-elements.spec.tspnpm typecheckclean againsthydrate-app.ts.Closes #6864