Skip to content

Per-scope takeover for live nodes whose server value is still streaming (D8 follow-up to #3817) #3819

Open

Description

@ryansolid

Problem

D8 (Stage 8, documentation/plans/stage8-connection-transport.md) makes a live node take over, meaning it re-runs its compute and opens the live connection, when its own hydration scope releases. For a node in the shell, that's when the root pass ends. Its stated goal is "No live node waits on another boundary."

#3817 (fixing #3764) added an exception. A live node whose serialized value is still in flight when it arms takes over at hydration end, after the last streamed boundary on the page has hydrated. Nodes with a loadingValue are exempt. The fallback is needed because the boundary that reads the node claims its server DOM against that value. If the node takes over before the value arrives, it has nothing to replay, and the boundary can't claim: you get a duplicate or unclaimed DOM. That happens with the real live() transport too, since its local first yield on takeover is the value the node adopted, and there isn't one yet.

The cost is latency. A live source created in the shell and read only inside a streamed <Loading> now goes live only when the slowest boundary on the page hydrates. In practice that covers nearly every real source in that shape: a shell memo read only inside <Loading> misses the shell flush unless its first value is ready synchronously. In a server probe, three microtasks were already too late.

Motivating case: the room demo

examples/room's header creates presence in the shell and reads it inside <Loading>. The Archive panel lower on the page takes 4 s. With the fallback, the tab joins the room, and other tabs see it join, only after the Archive lands. The demo exists to show the opposite. Its comments now note the exception.

Why the client alone can't do better

The ideal gate is "take over once every boundary that reads this node has hydrated." The client can't know that set. When the root pass ends, a pending boundary is an owner with no children, because its children are created when its fragment arrives. So until each boundary hydrates, nothing on the client can tell whether it will read the node. Walking the node's current observers only sees readers that already exist.

Candidate directions

  1. Server-recorded readers.
    • During SSR, record for each serialized shell node the ids of the streamed boundaries that read it, and ship that list with the payload, either beside the value or in the readers' fragment data.
    • On the client, the node's gate counts down as those boundaries release, falling back to hydration end, and nodes read by no boundary keep root scope.
    • This preserves D8 exactly, at the cost of a read hook on the server memo path, payload bytes, and an estimated 120–250 B minified on the client.
  2. Take over once the node's own value has arrived, replaying it.

Either direction should keep #3817's tests (both case-A timings in packages/web/test/hydration/live-shell-source-3764.spec.tsx) and the loadingValue test passing. It should also add a test for a node read by a fast boundary while an unrelated slow boundary is pending, which should connect before the slow boundary lands.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions