Repository navigation
fix(octane): defer JSX returned by direct calls of named functions - #1378
Merged
Merged
Conversation
A named `function` declaration that returns JSX compiled through the component-like return-JSX path, which evaluated its non-literal props and children during the call (the server even rendered the value to HTML then). Arrows, methods, function expressions, nested returns, and native-signal mode all defer the record until it renders, so the same markup read different context depending on how its function was declared, and fragment roots and `.map()` rows in such functions disagreed between SSR and the client. Direct calls now return a value that resolves where it renders. Body calls (`<Row />`) are detected by the scope the runtime already passes as argument 1 (`isRenderCall`) and keep the compiled fragment. The record is printed once in a hoisted `Fn$record(captures)`; a direct call wraps it with `deferRecord`, so body calls allocate nothing extra (an inline closure made V8 context-allocate every captured local on every call). The server hoists its direct branch into `Fn$direct(captures)`. Reassigned captured locals, `this`, and `arguments` keep an inline closure so the value reads live bindings. The fold tests' ad-hoc server loaders move to the shared fixture loader, which already resolves `octane/internal/server`, and the eval client bridge exposes the two new compiler helpers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
September 28, 2026 18:02
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: Stable children skip server deferral
- Removed the stableNames argument from jsxValueChildrenNeedRenderScope calls in directCallReturnKind so that identifier children (renderables) are no longer treated as static, forcing the server to take the deferred path that matches the client.
Or push these changes by commenting:
@cursor push 741d38f7ab
Preview (741d38f7ab)
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
@@ -20671,11 +20671,10 @@
if (requiresTemplateNormalization(node, 'html', true, ctx)) return 'fragment';
const stable = directCallStableNames(fn);
if (node.type !== 'Element' && node.type !== 'JSXElement') {
- return jsxValueChildrenNeedRenderScope(node, false, stable) ? 'value' : null;
+ return jsxValueChildrenNeedRenderScope(node, false) ? 'value' : null;
}
if (isComponentTag(node)) return 'value';
- return jsxValueRootNeedsRenderScope(node, stable) ||
- jsxValueChildrenNeedRenderScope(node, false, stable)
+ return jsxValueRootNeedsRenderScope(node, stable) || jsxValueChildrenNeedRenderScope(node, false)
? 'fragment'
: null;
}You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 7483954. Configure here.
Treating unreassigned parameters and top-level locals as static is sound
for the client record, which only stores hole values and interprets them
where the value mounts. The server's body call renders holes to HTML
immediately, so a direct call whose only hole was such a local, like
`Frame({ children: <ReadContext /> })`, rendered `children` in the caller's
scope while the client rendered it under the provider.
The server now classifies every non-literal hole as needing deferral again;
only the client's branch decision uses stable locals. Client output is
unchanged.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
JSX returned by a direct call of a named
functiondeclaration now resolves its non-literal props and children where the value renders, like JSX returned by an arrow function or method. Rendering the same function as a component (<Row />) is unchanged.Why. In default (non-native-signal) mode, only a top-level named
FunctionDeclarationwhosereturn <jsx>is not nested went through the component-like return-JSX path. That path evaluated holes during the call. Every other form deferred:const f = function f(){},export default function () {}, anif-nested return in the same function, arrows, methods, and all of native mode. Values from named declarations therefore contradicted #361's "JSX values follow the represented render scope" contract, whichSharedDescriptorProviderspins. The server also rendered such calls to HTML immediately. As a result, fragment roots and.map()rows returned from these functions server-rendered with the caller's context while the client deferred them, and hydration silently patched the mismatch. Direction confirmed with the maintainer: follow the rendered tree.Evaluation matrix before this change (default mode;
.tsrx=.tsx, dev = prod).map()inside the top-level returnif-nested return, nested declaration, function expression, arrow, methodAfter this change, every row defers on a direct call.
How
body(props, scope, extra)with that Scope current. The new internal helperisRenderCall(arg1)in both runtimes tests that condition. The probe uses a spare default parameter, which keepsfn.lengthunchanged and avoids anargumentsobject. When the function already has a second parameter that it never reassigns, the probe compares that parameter instead.Fn$record(captures). A body call invokes it directly. A direct call returnsdeferRecord(Fn$record, …captures), which wrapscreateScopedValue. Static records, native mode, and binding views are unchanged.ssrHtmltemplate. A direct call returns a deferred descriptor built in a hoistedFn$direct(captures), pairing with the client the same way native mode already pairs compiled fragments with the server's_sfragfold. Hoisted head elements register only on body calls, so a deferred value registers its own on render. The server also defers component and fragment roots, because its body call would otherwise render them to HTML at call time.this,arguments, ornew.target, keeps an inline closure. Hoisting passes values by argument, and a copy could differ from the live binding at render time.<Glyph top={top} />), because the client record only stores those values and interprets them where it mounts. The server's body call renders holes to HTML immediately, so the server defers every non-literal hole.Performance evidence
Body calls happen on every render of every return-JSX (
.tsx-style) component, so this path is hot. Baseline ismainat 867ab3a. The harness uses the same compiled components with each checkout's compiler and runtime (prod, esbuild-bundled), one fresh process per sample, and interleaved A/B pairs.Row216/248/232 B in TurboFan/--jitless/Maglev, identical to baseline, and likewiseRowWithSetupandStatic. Rejected designs cost more: an inline direct-branch closure added +40 B per call, because V8 context-allocates captured locals on every call;arguments[1]added +136 B.Row1.012,RowWithSetup1.014; mounted update of 1,000<Row/>0.989. The A/A noise band is about ±1–3%.--jitless: isolated body call +9% (theisRenderCallcall plus$record); mounted update of 1,000 rows +0.5%.renderToStringof 1,000 return-JSX rows gives B/A 1.000 (A/A 0.996)..tsx; prod compile, esbuild minify): +2.07% minified, +2.2–2.5% gzip. Most of it is in visx/xyflow (+6–7% minified: many small components, each with several captures).@{}code is unaffected.bundle-sizesuite: onlyoctane-jsxchanges, from 70,966 to 71,289 B gzip (+323 B: app +71, framework +252 fordeferRecordand scoped values), still withinjsx-budgets.json. All other apps are byte-identical.Validation
pnpm format:checkpnpm typecheckpnpm test: the full run aborts withJavaScript heap out of memoryon this machine; a concurrent full run on a branch one commit frommainended the same way, and both runs had the same twobase-ui-pristine-browserfailures. Files that failed under that memory pressure pass when run alone:octane-prodbasic, boundary-unwind, behavior-handoff-bundle, behavior-root, and conformance/fragment-refs-misc, plus the browser behavior-root and signals-native-collection. Relying on CI for the complete run.returned-jsx-direct-calls,scoped-jsx-values,directive-value-position,switch-fold,try-fold,ssr-dynamic-component-tags, and alloctane-evalsuser-app graders, across theoctane+octane-prod+octane-evals-user-appsprojects (1,156 tests at 04b94c2).The new
returned-jsx-direct-calls.test.tscovers TSRX, TSX, and native TSRX, each through client render, SSR, and hydration. Hydration assertions check node adoption, node counts, and the absence of mismatch diagnostics. Scenarios: exported, module-local, and default-exported declarations; fragment root; mapped rows; component root; document metadata; template directive; block-scopedvar; reassigned local; a renderable parameter (Frame({ children: <ReadContext /> }), added for the Bugbot finding); several parameters. Also covered: component use as the control, eager setup statements, a value built outside rendering and resolved per provider across updates and server requests, and a local changed after the call. On the baseline compiler, 104 of these fail (all default mode) and native passes. Breaking nested-varcapture or the reassignment guard makes the corresponding tests fail.switch-fold,try-fold, andssr-dynamic-component-tagsnow use the sharedloadCompiledFixtureSource, with the same compile ids. Their hand-rolled loaders only rewroteoctane/serverimports.packages/octane-evals/tests/_client-runtime.tsexposes the two new compiler helpers through its bounded bridge.Risk / follow-ups
decorate()pattern belongs here; the remedy documented for arrows (read into a local first) applies.type: _frag$N), socloneElementon it drops added props on both client and server; this is pre-existing. On the server,isValidElementof such a value is nowtrue, where it was previously an HTML carrier.isRenderCall. No runtime exports mutable bindings today, so I left that out.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
High Risk
This is a deliberate semantic change in core JSX evaluation and SSR/hydration for a common pattern (direct calls of return-JSX functions), with broad compiler and runtime surface area.
Overview
Direct calls of named
functiondeclarations that return JSX now defer non-literal props and children until the value renders, matching arrow functions and methods. Using the same function as a component (<Label />) is unchanged.The compiler splits body call vs direct call with
isRenderCall(scope)(argument 1 is the current Scope only when the renderer invokes the function as a component body). Direct calls returndeferRecord/ scoped values on the client and paired deferred SSR on the server, including fragment roots and mapped rows that previously rendered eagerly on the server. Setup code beforereturnstill runs during the call.Docs in
differences-from-react.mddescribe the behavior. Newreturned-jsx-direct-callstests cover client, SSR, and hydration across TSX/TSRX/native; a few server tests now useloadCompiledFixtureSource.Reviewed by Cursor Bugbot for commit 04b94c2. Bugbot is set up for automated code reviews on this repo. Configure here.