Skip to content

fix: rebuild a scoped JSX child only for the contexts it read - #602

Merged
WebEferen merged 2 commits into
mainfrom
fix/scoped-jsx-prop-identity
Aug 7, 2026
Merged

WebEferen merged 2 commits into
mainfrom
fix/scoped-jsx-prop-identity

Conversation

@WebEferen

@WebEferen WebEferen commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

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:check
  • pnpm typecheck
  • pnpm test
  • targeted tests:

Risk / follow-ups

Provenance

  • An agent produced this diff (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.

createScopedValue and deferred children in createScopedElement stop keying rebuilds on COMPILER_CACHE_CONTEXT_EPOCH. While a descriptor resolves, context reads are recorded (SCOPED_READ_TRACKING in readContextFrom); rebuild happens only if scopedReadsChanged says a read context’s $$version moved, 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.

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.
@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
octane-website Ready Ready Preview Aug 7, 2026 1:46pm
octane-website-mcp Ready Ready Preview Aug 7, 2026 1:46pm

Request Review

@github-actions github-actions Bot added the fix PR: bug fix label Aug 7, 2026
@WebEferen
WebEferen merged commit ce68bb8 into main Aug 7, 2026
34 checks passed
@WebEferen
WebEferen deleted the fix/scoped-jsx-prop-identity branch August 7, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants