Skip to content

fix: give method-style custom hooks their own component update boundary - #761

Merged
trueadm merged 1 commit into
octanejs:mainfrom
dudusotero:fix/member-form-hook-component-boundary
Aug 15, 2026
Merged

trueadm merged 1 commit into
octanejs:mainfrom
dudusotero:fix/member-form-hook-component-boundary

Conversation

@dudusotero

@dudusotero dudusotero commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • A component whose only hook is method-style (obj.useThing()) was classified hookless by the componentSlotLite eligibility pre-pass, so it was mounted with no block of its own. Its hook state and forceUpdate belonged to the parent, and updating that hook re-rendered the parent and every sibling.
  • The eligibility body walk now applies the same 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 a createXContext() factory. In this repo alone there are 78 such call sites across .tsrx/.tsx sources, including RTK Query's canonical api.useGetValueQuery(...) in @octanejs/redux-toolkit and store.useQuery(...) / store.useClientDocument(...) in @octanejs/livestore.

The two compiler passes disagreed about the same syntax. compile.js already 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 as withSlot(sym, () => obj.useX(...args, sym)) precisely because they are hooks. The eligibility pre-pass never learned the same thing: its unknown-call rule inspects only Identifier callees, and the free-identifier sweep ahead of it only sees bare names, so neither test can observe api.useCounter() — the receiver is api and the callee is a MemberExpression.

This was found while porting @xstate/react to Octane. createActorContext() returns useSelector/useActorRef that consumers call in exactly this shape (it is the form used throughout upstream's README and all 13 of its createActorContext tests), 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-computed MemberExpression with a use[A-Z] property name. Fails closed — matching only forfeits the lite path, never correctness.
  • packages/octane/tests/member-hook-boundary.test.ts and packages/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.
  • Changeset.

Validation

  • targeted: 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-prod
  • vitest --project redux-toolkit (11), --project livestore (30), --project tanstack-store (46), --project zustand (17) — the projects whose fixtures use member-form hooks
  • pnpm format:files:check on the changed paths
  • pnpm test (full) — not run; the affected projects above were run individually
  • pnpm typecheck — not run; the change is inside a .js compiler module with no type surface

Performance, per .rulesync/rules/core-engineering.md:

  • benchmarks/codegen-size compiles byte-identically before and after (raw 152564, min 75164, gz(min) 26774), so components that genuinely have no hooks keep componentSlotLite exactly as before.
  • Compile time is unchanged within measurement noise: interleaved best-of-7 over 200 compiles gave baseline 359.3 / 362.9 / 366.3 ms and candidate 362.2 / 365.7 / 372.0 ms. The ranges overlap; no claim is made in either direction.
  • Where the fix does apply, one componentSlotLite call becomes componentSlotVoid — +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

  • The predicate matches any non-computed member call with a 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 same use*-is-reserved convention the slot-injection pass already relies on, and the cost is one lost optimization rather than a behavior change.
  • Computed access (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

  • An agent produced this diff (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 componentSlotLite classification 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 componentSlotLite eligibility body walk in compile.js now rejects lite mounting for non-computed member calls whose property matches the same use[A-Z] rule the slot-injection pass already uses. Hookless components are unchanged; affected sites emit componentSlotVoid instead (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.

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.
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Aug 15, 2026
@dudusotero
dudusotero marked this pull request as ready for review August 15, 2026 04:23
@trueadm
trueadm merged commit 1cb4a19 into octanejs:main Aug 15, 2026
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants