Repository navigation
fix: give method-style custom hooks their own component update boundary - #761
Merged
trueadm merged 1 commit intoAug 15, 2026
Merged
Conversation
The componentSlotLite eligibility pre-pass only inspected Identifier callees, so a component whose only hook was member-form (obj.useThing()) looked hookless. It was mounted through the lite path with no block of its own, its hook cells and forceUpdate belonged to the parent, and updating that hook re-rendered the parent and every sibling. The slot-injection pass already treats these calls as hooks. Apply the same use[A-Z] convention to the member callee's property name in the eligibility walk. It fails closed: matching only forfeits the lite path, never correctness.
dudusotero
marked this pull request as ready for review
August 15, 2026 04:23
9 tasks done
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
obj.useThing()) was classified hookless by thecomponentSlotLiteeligibility pre-pass, so it was mounted with no block of its own. Its hook state andforceUpdatebelonged to the parent, and updating that hook re-rendered the parent and every sibling.use[A-Z]convention to a member callee's property name that the slot-injection pass already applies to these calls.Why
The object-carried hook is how a large part of the React ecosystem exposes hooks:
route.useLoaderData(),api.useGetThingQuery(), and every hook returned by acreateXContext()factory. In this repo alone there are 78 such call sites across.tsrx/.tsxsources, including RTK Query's canonicalapi.useGetValueQuery(...)in@octanejs/redux-toolkitandstore.useQuery(...)/store.useClientDocument(...)in@octanejs/livestore.The two compiler passes disagreed about the same syntax.
compile.jsalready carries a dedicated method-style branch in slot injection, whose own comment names the motivating cases — "METHOD-style custom hooks —route.useLoaderData(),api.useSearch()" — and wraps them aswithSlot(sym, () => obj.useX(...args, sym))precisely because they are hooks. The eligibility pre-pass never learned the same thing: its unknown-call rule inspects onlyIdentifiercallees, and the free-identifier sweep ahead of it only sees bare names, so neither test can observeapi.useCounter()— the receiver isapiand the callee is aMemberExpression.This was found while porting
@xstate/reactto Octane.createActorContext()returnsuseSelector/useActorRefthat consumers call in exactly this shape (it is the form used throughout upstream's README and all 13 of itscreateActorContexttests), and per-component selector bail-out — the reason the API exists — did not work.Changes
packages/octane/src/compiler/compile.js: reject lite eligibility for a call whose callee is a non-computedMemberExpressionwith ause[A-Z]property name. Fails closed — matching only forfeits the lite path, never correctness.packages/octane/tests/member-hook-boundary.test.tsandpackages/octane/tests/_fixtures/member-hook-boundary.tsrx: one custom hook reached both ways, with a hookless sibling, asserting that an update from either call shape re-renders only the component that owns the hook.Validation
packages/octane/tests/member-hook-boundary.test.ts— fails before the fix with['MemberParent', 'MemberHookChild:1', 'HooklessSibling']against the expected['MemberHookChild:1'], passes after. The identifier-form control passes in both states, so the test isolates the defect. Breaking the predicate deliberately turns it red again and restoring it turns it green.vitest --project octane --project octane-prodvitest --project redux-toolkit(11),--project livestore(30),--project tanstack-store(46),--project zustand(17) — the projects whose fixtures use member-form hookspnpm format:files:checkon the changed pathspnpm test(full) — not run; the affected projects above were run individuallypnpm typecheck— not run; the change is inside a.jscompiler module with no type surfacePerformance, per
.rulesync/rules/core-engineering.md:benchmarks/codegen-sizecompiles byte-identically before and after (raw 152564, min 75164, gz(min) 26774), so components that genuinely have no hooks keepcomponentSlotLiteexactly as before.componentSlotLitecall becomescomponentSlotVoid— +28 bytes of emitted output on the regression fixture for the component that gains a real block. That block is the correctness requirement, not an avoidable cost.Risk / follow-ups
use[A-Z]property, so a non-hook method that happens to be named that way (vi.useFakeTimers()) now also forfeits lite eligibility for its enclosing component. That is the sameuse*-is-reserved convention the slot-injection pass already relies on, and the cost is one lost optimization rather than a behavior change.obj['useThing']()) is still not detected. The slot-injection pass does not handle it either, so the two passes stay consistent; a component reaching a hook that way was already unsupported.Provenance
agent-authored)Note
Medium Risk
Compiler emission path change for components using member-form hooks; behavior fix aligns with existing slot-injection semantics and is covered by a targeted regression test.
Overview
Fixes incorrect
componentSlotLiteclassification when a component's only hook is called as a member (api.useCounter(),route.useLoaderData(), etc.). Those components were treated as hookless and mounted without their own block, so hook updates re-rendered the parent and siblings.The
componentSlotLiteeligibility body walk incompile.jsnow rejects lite mounting for non-computed member calls whose property matches the sameuse[A-Z]rule the slot-injection pass already uses. Hookless components are unchanged; affected sites emitcomponentSlotVoidinstead (small codegen increase where isolation is required).Adds a regression fixture and Vitest comparing identifier vs member hook call shapes with a hookless sibling, plus a changeset.
Reviewed by Cursor Bugbot for commit ff6119f. Bugbot is set up for automated code reviews on this repo. Configure here.