Skip to content

fix: buffer rsc:update payloads arriving before dev client mounts#161

Merged
uhyo merged 2 commits into
masterfrom
claude/issue-145-9sk4wl
Jul 21, 2026
Merged

fix: buffer rsc:update payloads arriving before dev client mounts#161
uhyo merged 2 commits into
masterfrom
claude/issue-145-9sk4wl

Conversation

@uhyo

@uhyo uhyo commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #145.

In devMain (packages/static/src/client/entry.tsx), the rsc:update HMR listener is registered immediately, but setPayload was only assigned inside the component's mount effect. An update event arriving before the first effect ran (e.g. a server-code edit racing initial render, or a slow mount on the SSR failure path) called setPayload while it was still undefined, throwing a TypeError and dropping the update.

Changes

  • fetchRscPayload now checks whether setPayload is assigned; if not, the fetched payload is stored in a pendingPayload variable instead of crashing.
  • The mount effect applies any pending payload right after assigning setPayload, so early updates are rendered rather than dropped.

Testing

  • pnpm typecheck
  • pnpm lint
  • pnpm test:run (102 tests passed)

🤖 Generated with Claude Code

https://claude.ai/code/session_01CAcPFym3wyHJQyMb2FdgqT


Generated by Claude Code

In devMain, the rsc:update HMR listener was registered before the
component's mount effect assigned setPayload, so an update event racing
the initial render called undefined and threw, dropping the update.
Keep the fetched payload in a pending variable when the setter is not
ready yet and apply it from the mount effect.

Fixes #145

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CAcPFym3wyHJQyMb2FdgqT
Comment thread packages/static/src/client/entry.tsx Outdated
)}`;
const payload = await createFromFetch<RscPayload>(fetch(rscUrl));
setPayload(payload);
if (setPayload) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving the pre-effect logic into the initial value of setPayload instead of branching here?

Per review, replace the undefined check in fetchRscPayload with an
initial setPayload implementation that stashes the payload until the
mount effect swaps in the real setter.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CAcPFym3wyHJQyMb2FdgqT
@uhyo
uhyo merged commit 96bf550 into master Jul 21, 2026
2 checks passed
@uhyo
uhyo deleted the claude/issue-145-9sk4wl branch July 21, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants