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.
Problem
In
devMain(packages/static/src/client/entry.tsx),setPayloadis only assigned inside auseEffect: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) callssetPayload(...)while it is stillundefined, throwing aTypeErrorand 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.