Skip to content

Commit 3af4696

Browse files
ryansolidclaudecursoragent
authored
fix(web): async dynamic() serializes its landing and the client adopts it (#3666) (#3671)
* fix(web): async dynamic() serializes its landing and the client adopts it (#3666) dynamic() no longer opts its memo out of hydration serialization. The factory memo boxes a thenable the source returns so it stays sync-valued (hoisted factories have no id); the per-instance value memo unboxes it and is an ordinary async memo — its landing serializes under the instance id and the client memo adopts the record during hydration instead of re-running the source and waiting on it, the pending beat that committed the enclosing <Loading> to a fallback the server never rendered. - Server component landings cross as flight references; `_$SC.r(id, address)` now resolves to the call's COMPONENT_BINDING so the adopted value passes `sameInstance` and mounts carry the address. Any async wrapper around a server reference (router query(), an async arrow) hydrates the same as a direct call. - A client component function landing cannot cross: new diagnostic DYNAMIC_ASYNC_COMPONENT — recorded on the observe channel, the memo rejects in every tier (dev with guidance, prod with the code). - deferStream still holds the shell for both source-async (the value memo's option) and dependency-async (the block on a NotReady the source threw). - Sync sources unchanged: no record is written. Wire shape: one hydration record per async dynamic() instance; one more hydration owner id per dynamic() instance. Artifacts re-recorded where the spec is the recorder; the 8 specs that resolved async sources to client component functions are rewritten to server components / tag names. Co-authored-by: Claude <[email protected]> Agent: Claude via Cursor Co-authored-by: Cursor <[email protected]> * chore(size): ratchet CSR app and frames eager consumer for #3671 CSR app 15.99 -> 16.04 KB: measured 16,025 B against next's 15,967 (+58 B, 35 B over). Brotli layout drift — the scenario never imports dynamic(), the minified bundle is 45,297 B on both sides and differs only in esbuild's short-name assignment. Frames eager consumer 12.40 -> 12.42 KB: measured 12,410 B against next's 12,367 (+43 B, 10 B over). +98 B minified in the frames client's fallback _$SC bootstrap, which now mints address-bound COMPONENT_BINDING bindings. Co-authored-by: Claude <[email protected]> Agent: Claude via Cursor Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Claude <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 1a7d14f commit 3af4696

44 files changed

Lines changed: 1385 additions & 191 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"@solidjs/web": patch
3+
"@solidjs/signals": patch
4+
"solid-js": patch
5+
---
6+
7+
fix(web): an async `dynamic()` instance serializes its landing and the client adopts it (#3666)
8+
9+
`dynamic()` no longer opts its memo out of hydration serialization. The per-instance value memo is an ordinary async memo: when the source introduced async (returned a thenable during SSR) its landing is serialized under the instance's id and the client memo adopts the record during hydration instead of re-running the source and waiting on it — the pending beat that committed the enclosing `<Loading>` to a fallback the server never rendered, then missed the SSR'd nodes. A server component lands as a flight reference (`_$SC.r(id, address)` now resolves to the call's binding, so a wrapped `query()` or `async` arrow around a server reference hydrates the same as a direct call), a tag name as its string, and a sync source lands nothing — unchanged.
10+
11+
A source that resolves to a client component _function_ cannot serialize and is now refused on the server at the point the memo would serialize it — new diagnostic `DYNAMIC_ASYNC_COMPONENT` (recorded on the observe channel; the memo rejects into the nearest `<Errored>` / `onError` in every tier). Move the async upstream (`createAsync`/`createMemo` read synchronously by the source) or use `lazy()`.
12+
13+
Wire shape: each async `dynamic()` instance now writes one hydration record, and every `dynamic()` instance allocates one more hydration owner id (keys under a `dynamic()` element shift by one slot).

‎documentation/solid-2.0/03-control-flow.md‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,30 @@ Inside a `<For>` callback or other render function, the callback body is the pla
199199

200200
#### Async sources and `Loading`
201201

202-
`source` may return a `Promise<Component | string | undefined>`. The factory composes with `Loading` / `Errored` through the normal `NotReadyError` flow — no separate suspense primitive or user-side `await`.
202+
`source` may return a promise. The factory composes with `Loading` / `Errored` through the normal `NotReadyError` flow — no separate suspense primitive or user-side `await`. Each mounted instance is an ordinary async memo: under SSR its settled value is **serialized and the client adopts it during hydration** — the source is not re-run, the boundary is not re-entered, and the server-rendered nodes stand. That puts a contract on what an async source may resolve to, because the value has to cross the wire:
203+
204+
- **A server component** (`"use server"` function returning JSX, called directly or through a wrapper such as a router `query()`): crosses as a reference; the client adopts the frame the server rendered. This is the primary case.
205+
- **A tag name** (`"article"`): a serializable value; adopted as-is.
206+
- **A client component function**: cannot be serialized. In dev this is an error on the server, `DYNAMIC_ASYNC_COMPONENT` ([RFC 08](08-dev-diagnostics.md#dynamic_async_component)), and the memo rejects into the nearest `Errored`. The async does not belong in the source: resolve it upstream — a `createAsync` / `createMemo` the source reads synchronously — or use `lazy()` when what is being awaited is the component's code.
207+
208+
```jsx
209+
// A client component chosen by async data: the DATA is async, the source is sync.
210+
const page = createAsync(() => fetchPage(params.id));
211+
const Page = dynamic(() => (page().editable ? Editor : Viewer));
212+
213+
// Code-split client component: lazy(), not an async dynamic() source.
214+
const Editor = lazy(() => import("./Editor.jsx"));
215+
216+
// A server component answering an async call: the source may stay async.
217+
const Article = dynamic(() => loadArticle(params.id));
218+
```
219+
220+
A synchronous source (whatever it returns) never serializes anything; only a source that introduced async writes a hydration record.
203221

204222
Under SSR a pending source streams in behind its boundary by default — a source is data of unknown cost (a server component call, say). Pass `{ deferStream: true }` to hold the document's first flush until it settles, the same option `createMemo` takes ([RFC 05](05-async-data.md)); the client ignores it. This is the one place `dynamic` and `lazy` differ: a `lazy()` module load is code, not data, and always holds the shell — the shell cannot decide it has discovered all async until the segment's code has run — while the boundary still owns whatever async that code then discovers.
205223

206224
```jsx
207-
const Page = dynamic(() => loadPageComponent(params.id), { deferStream: true });
225+
const Article = dynamic(() => loadArticle(params.id), { deferStream: true });
208226
```
209227

210228
#### Notes

0 commit comments

Comments
 (0)