Repository navigation
fix: preserve guarded property reads in inferred hook dependencies - #1123
Merged
domgan-oai merged 6 commits intoSep 18, 2026
Merged
Conversation
domgan-oai
marked this pull request as ready for review
September 18, 2026 18:18
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.
Reviewed by Cursor Bugbot for commit 71f84f8. Configure here.
This was referenced Oct 6, 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.

Summary
Preserve control-flow guards when inferring hook dependencies without losing stable own data fields and callbacks. A guarded read such as
if (item) console.log(item.name)no longer invokes a property getter or throws on an absent receiver while rendering.Why
The dependency collector traversed conditional branches and possible exits as unconditional reads. Tracking only whole receivers avoided premature getters, but made effects rerun when props containers or subscribed-store snapshots changed despite stable fields and actions.
Changes
Track guarded branches and possible early exits during read-only dependency analysis. Consume labeled exits only at their own target. Extend the existing runtime dependency discriminator with a guarded descriptor probe: own data properties compare their values, accessors and inherited properties compare their receivers, and failed reflection probes fall back to receiver identity. Separate module-local nullish markers distinguish a failing receiver read from a successful own-data read of null or undefined. Update the full compiler and both plain-hook emitters together. Preserve ordinary method inference, explicit dependency arrays, opaque execution contexts and parsed AST immutability. Add generic runtime, server-rendering and hydration regressions, document the tradeoff, and include a patch changeset.
Validation
pnpm syncpass. The follow-up is signed and the worktree is clean.benchmarks/hook-memo/run.mjsruns against signed ed2416b and the current 005d980 implementation use Node 24.19.0 and the same installed dependencies. All semantic and observer controls pass; all recorded creation counters and compiled/bundled byte metrics are equal for these fixtures. This does not measure guarded native descriptor allocations or establish a timing improvement.Risk / follow-ups
Guarded descriptor probes allocate a descriptor on each applicable render. Accessors and inherited fields track broader receiver identities; arbitrary Proxy reflection can have side effects even though getter values are not evaluated. Ordinary unguarded method calls retain their allocation-free path. Compiler output using the guarded flag must be paired with the matching runtime.
Provenance
agent-authored)Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Changes compiler-inferred dependency arrays and
__methodDepruntime semantics; guarded descriptor probes allocate per render and Proxy reflection can have side effects, so compiler output must match the updated runtime.Overview
Inferred hook dependencies now respect control-flow guards so dependency comparison during render does not run property reads that the callback only performs behind a condition, early return, short-circuit, loop, or
try/catch.The dependency walker marks guarded member reads and method calls, including labeled
break/continueprecision, and emits__methodDep(root, name, true)from the full compiler and plain-hook paths. Guarded runtime probing usesgetOwnPropertyDescriptorfor own data values without calling getters; accessors and inherited properties compare the receiver; nullish receivers use distinct module-local symbols so missing receivers do not alias successfulnull/undefineddata reads.Unguarded method inference stays allocation-free. Docs and a patch changeset describe the behavior; new client, hydration, and fixture tests cover getters, optional receivers, memos, and reflection failures.
Reviewed by Cursor Bugbot for commit 005d980. Bugbot is set up for automated code reviews on this repo. Configure here.