Skip to content

Dev client entry: rsc:update arriving before mount crashes fetchRscPayload #145

Description

@uhyo

Problem

In devMain (packages/static/src/client/entry.tsx), setPayload is only assigned inside a useEffect:

let setPayload: (v: RscPayload) => void;
// ...
useEffect(() => {
  setPayload = (v) => startTransition(() => setPayload_(v));
}, [setPayload_]);

The import.meta.hot.on("rsc:update", ...) listener is registered immediately, so an update event that arrives before the first effect runs (e.g. a server-code edit racing initial render, or an SSR failure path where mounting is slow) calls setPayload(...) while it is still undefined, throwing a TypeError and dropping the update.

Suggested fix

Make the handler resilient: keep the latest payload in a module-level variable and have the component pick it up on mount, or simply guard setPayload?.(payload) and re-apply the pending payload from the effect.

Found during a framework audit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions