Repository navigation
perf: keep form-action and transition graphs out of event-only bundles - #946
Merged
Merged
Conversation
PR #943 let dispatchDelegated call the form-action submit handler directly, which made startTransition and the held-transition swap graph reachable from every bundle with delegated events. setFormAction, the only writer of $$formAction, now installs that handler through FORM_SUBMIT_DRIVER. The compiled setup checkpoint is emitted only when setup can schedule a render-phase self-update; passive built-in hooks and unshadowed pure globals cannot. Co-Authored-By: Claude Fable 5.1 <[email protected]>
trueadm
marked this pull request as ready for review
September 3, 2026 20:52
A memo factory, state initializer, or reducer passed by reference can call a setter without a visible body. Treat every argument to a sync-factory hook that could be a function as an unclassified call so the setup checkpoint stays. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Pure namespaces invoke callbacks unsafely
- Added SETUP_CALLBACK_NAMESPACE_METHODS set for Array.from/JSON.parse/JSON.stringify/Object.groupBy and applied walkInvokedArgument to their callback-position arguments (index 1+), so opaque references now correctly fail closed and emit the setup checkpoint.
Or push these changes by commenting:
@cursor push 2ea0aef45b
Preview (2ea0aef45b)
diff --git a/packages/octane/src/compiler/compile.js b/packages/octane/src/compiler/compile.js
--- a/packages/octane/src/compiler/compile.js
+++ b/packages/octane/src/compiler/compile.js
@@ -3918,7 +3918,7 @@
}
}
-// ─────────────────────────────────────────────────────────────────────────────
+// ───────────────────────────────────────────────��─────────────────────────────
// Dep-keyed hook-callback memoization (production compiles).
//
// The companion to the capture-free lift. A callback that DOES read component
@@ -4773,6 +4773,17 @@
'decodeURIComponent',
]);
const SETUP_PURE_GLOBAL_NAMESPACES = new Set(['Math', 'JSON', 'Number', 'Object', 'Array', 'Date']);
+// Namespace methods that synchronously invoke a callback argument. The callback
+// is always at argument index 1; earlier arguments are data. A mapper, reviver,
+// replacer, or classifier passed by reference cannot be entered, so its body is
+// opaque and must fail closed the same way sync-factory hook arguments do.
+const SETUP_CALLBACK_NAMESPACE_METHODS = new Set([
+ 'Array.from',
+ 'Array.fromAsync',
+ 'JSON.parse',
+ 'JSON.stringify',
+ 'Object.groupBy',
+]);
// Every binding name the module declares anywhere. A global namespace shadowed
// by any local, parameter, or import is treated as an unknown callee.
@@ -4876,7 +4887,15 @@
SETUP_PURE_GLOBAL_NAMESPACES.has(callee.object.name) &&
isGlobal(callee.object.name)
) {
- walk(n.arguments, true);
+ if (
+ callee.property?.type === 'Identifier' &&
+ SETUP_CALLBACK_NAMESPACE_METHODS.has(callee.object.name + '.' + callee.property.name)
+ ) {
+ if (n.arguments[0]) walk(n.arguments[0], true);
+ for (let i = 1; i < n.arguments.length; i++) walkInvokedArgument(n.arguments[i]);
+ } else {
+ walk(n.arguments, true);
+ }
return;
}
found = true;
diff --git a/packages/octane/tests/audit-hook-behavior.test.ts b/packages/octane/tests/audit-hook-behavior.test.ts
--- a/packages/octane/tests/audit-hook-behavior.test.ts
+++ b/packages/octane/tests/audit-hook-behavior.test.ts
@@ -581,6 +581,14 @@
expect(code).not.toContain(checkpoint);
});
+ it('omits the checkpoint for callback-accepting namespace methods with inline callbacks', () => {
+ const code = compiled(`
+ const mapped = Array.from(props.items, (x: any) => x.id);
+ const data = JSON.parse(props.text, (_k: string, v: any) => v);
+ `);
+ expect(code).not.toContain(checkpoint);
+ });
+
it.each([
[
'a setter called in setup',
@@ -605,6 +613,22 @@
'a shadowed global namespace',
`const Math = props.math;\nconst value = Math.max(props.n, 1);`,
],
+ [
+ 'Array.from with a mapper passed by reference',
+ `const mapped = Array.from(props.items, props.mapper);`,
+ ],
+ [
+ 'JSON.parse with a reviver passed by reference',
+ `const data = JSON.parse(props.text, props.reviver);`,
+ ],
+ [
+ 'JSON.stringify with a replacer passed by reference',
+ `const text = JSON.stringify(props.data, props.replacer);`,
+ ],
+ [
+ 'Object.groupBy with a classifier passed by reference',
+ `const groups = Object.groupBy(props.items, props.classify);`,
+ ],
])('keeps the checkpoint for %s', (_, body) => {
expect(compiled(body)).toContain(checkpoint);
});You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 81f7a79. Configure here.
…point analysis Array.from, JSON.parse/stringify callbacks, Object.groupBy, and similar can run user code by reference. Keep an explicit member allowlist and check the JSON callback positions like a hook factory. Co-Authored-By: Claude Fable 5.1 <[email protected]>
14 of 21 tasks
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.


Note
Low Risk
Changes are tree-shaking and compile-time emission guards with fail-closed checkpoint analysis; function form actions still depend on
setFormActioninstalling the driver, which new tests pin.Overview
Production bundles that only delegate events no longer pull in
handleFormSubmit,startTransition, and the held-transition graph.dispatchDelegatedinvokes a nullableFORM_SUBMIT_DRIVERthatsetFormActioninstalls when a function$$formActionis first wired, so specialized/static roots and click-only apps shrink by several KB gzip without changing submit behavior when a real function action exists.Compiled setup checkpoints (
__s.block.pendingearly return) are emitted only when static analysis decides setup can schedule a render-phase self-update. Passive built-in hooks and allowlisted pure globals no longer force the checkpoint; setters, sync-factory bodies, factories/initializers passed by reference, prop/custom-hook calls, and anything unclassified still do. Module binding names guard the global allowlist against shadowing.Adds reachability and behavior tests (production esbuild bundles, spread-mounted form actions, memo-factory mount replay) and audit doc measurements for the bundle-size follow-up.
Reviewed by Cursor Bugbot for commit 6ed5b20. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary
dispatchDelegatedno longer references the form-action submit handler directly.setFormAction, the only writer of$$formAction, installs aFORM_SUBMIT_DRIVER, so bundles that only delegate events (compiler-specialized roots, the CLI SPA starter) stop retainingstartTransitionand the whole held-transition swap graph (about 30 functions, roughly 4.1 KB gzip).if (__s.block.pending && !__s.block.crossRenderUpdate) return;) is emitted only when setup can schedule a render-phase self-update. Passive built-in hooks and unshadowed standard globals cannot; setters, custom hooks, prop callbacks, sync factories that call setters, factories or initializers passed by reference (any callable-shaped argument to a sync-factory hook fails closed), and any unclassified call keep it.Why
dispatchDelegated → handleFormSubmit → startTransition → ensureTransitionSwapDrivermade the transition machinery reachable from any bundle with delegated events. Before fix: address React behavioral audit defects #943 that path was only reachable throughsetFormAction.Measurements
Same environment for every column: Node 24.18.0, macOS ARM64, locked native parser,
pnpm install --offline. Base is 33720d8 (the PR base), main is 44d50db.node benchmarks/hook-memo/run.mjs(inline variant, gzip bytes / minified bytes):node benchmarks/bundle-size/run-minimal.mjs(gzip bytes):node benchmarks/codegen-size/run.mjs(compiled corpus, minified / gzip):Attribution of the residual growth on root-static-specialized after this branch (about 850 gzip bytes): the urgent-transition render handling in
renderBlockInner, the mount-time render-phase drain, delegated handler and submit snapshots, commit-phase error queue, Document/fragment root support, and the custom-element event checks. All are the fixed behaviors.What was not reduced, and why
createRootscenario keep their growth. Their entry retains the descriptor renderer, whose spread and host-prop paths own function form actions, so they already reached the transition graph before fix: address React behavioral audit defects #943 throughsetFormAction → handleFormSubmit → startTransition. That chain cannot be made lazy soundly: a spread orcreateElementprop decides at render time. The growth there is the new transition-hook records, queued state replay, and held-update reconciliation, which are the B-series fixes themselves.observeprop in setup, which is an unclassifiable call.event-names.jsstays runtime data: custom-element spread/descriptor props need the exact camel-case delegated set at render time; feature detection would diverge from React on the pinned corner cases.html-tree-validation.jswas already imported by the client runtime before fix: address React behavioral audit defects #943 (dev-only use, tree-shaken from production output), so it is not a contributor.process.env.NODE_ENV !== 'production'; none of their strings appear in the production bundles.benchmarks/bundle-sizeratio guards (node benchmarks/bench.mjs --ratios bundle-reachability) breach 66 times on main and on the pre-fix: address React behavioral audit defects #943 base: the committed budgets date from fix: stop the compiled @for path retaining the descriptor renderer #767 (2026-08-16) and that suite only runs in the weekly bench workflow. This branch improves the affected scenarios but I did not raise budgets; that needs a maintainer decision.Changes
packages/octane/src/runtime.ts:FORM_SUBMIT_DRIVER, installed bysetFormAction, invoked fromdispatchDelegated.packages/octane/src/compiler/compile.js:setupCanScheduleSelfUpdatereplaces the any-call rule for the setup checkpoint;collectModuleBoundNamesguards the global allowlist against shadowing; the allowlist is an explicit set of non-invoking members (Math.*,Number/Object/Array/Dateinspectors,JSON.parse/stringifywith their callback positions checked like hook factories), soArray.from,Object.groupBy, and any callback passed by reference keep the checkpoint.form-action-bundle.test.ts(production reachability with and without a function form action, executed in JSDOM), spread-installed form action after mount inaudit-events-portals.test.ts, memo-factory self-update replay plus checkpoint emission matrix inaudit-hook-behavior.test.ts. Each was confirmed red with its fix reverted.docs/divergence-audit-2026-09-03.md: follow-up measurements row.octanepatch.Validation
pnpm format:checkpnpm typecheckpnpm test: 28,733 passed, 2 failed as 5 s timeouts (hmr.test.tsprod'App'vite replacement,compiler/volar.test.tsspread-ref type check) during a 25-minute run under concurrent load; both files pass in isolation on this branch and on main (96/96). Locally the vitest orchestrator exhausts the default 4 GB heap on an unmodifiedmaincheckout too, so the run usedNODE_OPTIONS=--max-old-space-size=12288.octane,octane-prod):audit-hook-behavior,audit-events-portals,compiler-authored-hosts,host-update-contract,audit-list-diagnostics,audit-hook-diagnostics,universal-manual-hook-context,plain-hook-import-alias,actions,production-error-bundle,form-action-bundlenode benchmarks/hook-memo/run.mjsvalue/identity and observer controls passRisk / follow-ups
setFormActionstarts writing$$formAction, it must also install the driver; the reachability test pins the negative case and the spread/descriptor tests pin the positive one.Provenance
agent-authored)🤖 Generated with Claude Code