fix: buffer rsc:update payloads arriving before dev client mounts#161
Merged
Conversation
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
uhyo
commented
Jul 21, 2026
| )}`; | ||
| const payload = await createFromFetch<RscPayload>(fetch(rscUrl)); | ||
| setPayload(payload); | ||
| if (setPayload) { |
Owner
Author
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #145.
In
devMain(packages/static/src/client/entry.tsx), thersc:updateHMR listener is registered immediately, butsetPayloadwas 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) calledsetPayloadwhile it was stillundefined, throwing aTypeErrorand dropping the update.Changes
fetchRscPayloadnow checks whethersetPayloadis assigned; if not, the fetched payload is stored in apendingPayloadvariable instead of crashing.setPayload, so early updates are rendered rather than dropped.Testing
pnpm typecheckpnpm lintpnpm test:run(102 tests passed)🤖 Generated with Claude Code
https://claude.ai/code/session_01CAcPFym3wyHJQyMb2FdgqT
Generated by Claude Code