Skip to content

Commit 551ef0d

Browse files
fix(web): restore render context before awaited-path root hole retries (#4601)
An awaited renderToStream()'s drain re-pulls root holes without restoring sharedConfig.context first — unlike doShell, which performs the restore for the piped paths. A resumed render body then runs under whichever concurrent render set the global last, so an async memo created there records into (and adopts from) another render's slot store under the same hydration id and serves that render's value. Mirrors the doShell contract for the awaited thenable drain (#4595).
1 parent 87f3446 commit 551ef0d

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/web": patch
3+
---
4+
5+
An awaited `renderToStream()` that re-pulls root holes — as happens when a `lazy()` component's first load is shared across concurrent renders — now restores the render's `sharedConfig.context` first, the same restore the streamed path already performs in `doShell`. Without it the resumed render body runs under whichever concurrent render set the global last, so an async memo created there records into (and adopts from) another render's slot store and concurrent requests can read each other's values (#4595).

‎packages/web/src/server.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3550,6 +3550,13 @@ export function renderToStream(code, options = {}) {
35503550
// The wind-down already completed this consumer; a re-pull on
35513551
// the disposed render would only find another failure.
35523552
if (dead) return;
3553+
// Same restore doShell performs, for the same reason: re-pulled
3554+
// root holes re-enter render code that captures
3555+
// `sharedConfig.context` (a memo's settle ctx, lazy()'s asset
3556+
// registration), and the global is whichever render ran last —
3557+
// without it a resumed body creates and records into another
3558+
// concurrent request's context (#4595).
3559+
sharedConfig.context = context;
35533560
// Same gates as doShell: pending root head props are shell
35543561
// blockers, so flushEnd must not run ahead of them (their
35553562
// source may not be serialized, so the serializer alone
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
*
4+
* #4595: concurrent awaited renderToStream()s that share a lazy()
5+
* component's first load resume their root holes without restoring the
6+
* render's `sharedConfig.context` — the resumed body runs under whichever
7+
* render set the global last, so an async memo created there records into
8+
* (and adopts from) another render's slot store under the same hydration
9+
* id and serves that render's value.
10+
*/
11+
import { expect, test } from "vitest";
12+
import { renderToStream } from "@solidjs/web";
13+
import { createMemo, lazy } from "solid-js";
14+
15+
const later = <T,>(value: T, ms: number) => new Promise<T>(r => setTimeout(() => r(value), ms));
16+
17+
// Each render's page: its own tag, and an async memo resolving to it.
18+
function Page(props: { tag: string }) {
19+
const bag = createMemo(() => later({ tag: props.tag }, 5));
20+
return (
21+
<main>
22+
<p id="v">{`${props.tag}:${bag().tag}`}</p>
23+
</main>
24+
);
25+
}
26+
27+
// Module-level `lazy()`, as a router's lazy route is: the six concurrent
28+
// renders below share its first load.
29+
const LazyPage = lazy(async () => ({ default: Page }));
30+
31+
test("concurrent awaited renders sharing a lazy()'s first load each read their own async memo's value", async () => {
32+
const tags = ["a", "b", "c", "d", "e", "f"];
33+
const pages = await Promise.all(
34+
tags.map(tag => renderToStream(() => <LazyPage tag={tag} />, { manifest: {} }).then(String))
35+
);
36+
const seen = pages.map(html => /<p id="v">(?:<!--[^>]*-->)*([^<]*)/.exec(html)?.[1]);
37+
expect(seen).toEqual(tags.map(tag => `${tag}:${tag}`));
38+
});

0 commit comments

Comments
 (0)