Repository navigation
fix: rebuild a scoped JSX child only for the contexts it read - #602
Merged
Merged
Conversation
A component's children resolve lazily, in the scope they render in, so each one is a thunk that builds its element and props object on demand. That thunk was rebuilt whenever a single global context epoch moved, and it moved on every provider value change anywhere in the tree. The rebuild re-ran the thunk, so the props object came back new along with every inline callback written at that call site, even though the owning component never rendered again. Effect, callback and memo deps are keyed on those identities, so they churned on every unrelated provider update, and memo() on such a child could not bail. Where one of those effects wrote state feeding the same provider the cycle never converged: @octanejs/radix Form did exactly that, re-registering a custom matcher once per frame for as long as the form stayed mounted. Reads are now collected while a record resolves and re-checked against each context's version, so a record that reads no context keeps the props it was given. Scope changes matter only to records that did read context, which still keeps one shared descriptor from serving two providers; without that, host classification alternating between the parent and child block rebuilt on every render by itself.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
trueadm
approved these changes
Aug 7, 2026
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.
A component's children resolve lazily, in the scope they render in, so each one is a thunk that builds its element and props object on demand. That thunk was rebuilt whenever a single global context epoch moved, and it moved on every provider value change anywhere in the tree. The rebuild re-ran the thunk, so the props object came back new along with every inline callback written at that call site, even though the owning component never rendered again.
Effect, callback and memo deps are keyed on those identities, so they churned on every unrelated provider update, and memo() on such a child could not bail. Where one of those effects wrote state feeding the same provider the cycle never converged: @octanejs/radix Form did exactly that, re-registering a custom matcher once per frame for as long as the form stayed mounted.
Reads are now collected while a record resolves and re-checked against each context's version, so a record that reads no context keeps the props it was given. Scope changes matter only to records that did read context, which still keeps one shared descriptor from serving two providers; without that, host classification alternating between the parent and child block rebuilt on every render by itself.
Summary
Validation
pnpm format:checkpnpm typecheckpnpm testRisk / follow-ups
Provenance
agent-authored)Note
Medium Risk
Touches core lazy JSX resolution in
runtime.ts; wrong invalidation could stale context-dependent children or over-rebuild, but behavior is narrowly scoped with new regression tests.Overview
Fixes unstable prop/callback identities when a parent renders once but lazy scoped children keep re-resolving because any provider bumped a global context epoch.
createScopedValueand deferred children increateScopedElementstop keying rebuilds onCOMPILER_CACHE_CONTEXT_EPOCH. While a descriptor resolves, context reads are recorded (SCOPED_READ_TRACKINGinreadContextFrom); rebuild happens only ifscopedReadsChangedsays a read context’s$$versionmoved, or—only for records that read context—the resolving scope is no longer the same. Records that never read context are not rebuilt on unrelated provider updates, so inline callbacks and props objects keep stable references. Scope alone no longer forces rebuild, fixing parent/child host-classification scope alternation that was recreating props every render.Adds a changeset and Vitest coverage (
scoped-jsx-prop-identity) for stable callback identity across related/unrelated context bumps and lazy context props still updating.Reviewed by Cursor Bugbot for commit 34f9a1f. Bugbot is set up for automated code reviews on this repo. Configure here.