Repository navigation
fix: form Float precedence groups in tree discovery order on client mounts - #739
Merged
Merged
Conversation
…ounts Precedence group order is CSS cascade order. Client mounts created groups in body-completion order, so a nested child's or @Try arm's group could precede its parent's and the same tree cascaded differently on a client-only mount than on an SSR'd page. Resource registrations now run after a component's setup but before its constructs mount children, forming groups parent-first with suspended arms at reveal — matching SSR and React. The server twin fixes a latent TDZ crash the placement rule exposed: a hoisted head element or Float resource whose attribute reads a setup local emitted its registration ahead of the local's declaration and threw at render. Capture-free head statements keep the historical front placement (arm-root sheets still ship with the streaming shell); capturing ones now run right after setup, still ahead of the children the return renders. Adjudicates the client group-order item from #711 as "fix". Co-Authored-By: Claude Fable 5 <[email protected]>
23 of 27 tasks
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: SSR head partition reorders groups
- Changed the SSR head partition to defer all statements after the first capturing one, preserving source order across the front/deferred boundary and matching the client's sequential registration.
Or push these changes by commenting:
@cursor push 8f4a0eb18e
Preview (8f4a0eb18e)
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
@@ -9783,15 +9783,17 @@
for (const s of inlinedSubs) collectStatementBindings(s, bodyBindings);
if (bodyBindings.size > 0) {
frontHead = [];
+ let seenCapture = false;
for (const stmt of headStatements) {
- let captures = false;
- for (const free of collectFreeIdentifiers(stmt, [])) {
- if (bodyBindings.has(free)) {
- captures = true;
- break;
+ if (!seenCapture) {
+ for (const free of collectFreeIdentifiers(stmt, [])) {
+ if (bodyBindings.has(free)) {
+ seenCapture = true;
+ break;
+ }
}
}
- (captures ? deferredHead : frontHead).push(stmt);
+ (seenCapture ? deferredHead : frontHead).push(stmt);
}
}
}
diff --git a/packages/octane/tests/_fixtures/float-group-order.tsrx b/packages/octane/tests/_fixtures/float-group-order.tsrx
--- a/packages/octane/tests/_fixtures/float-group-order.tsrx
+++ b/packages/octane/tests/_fixtures/float-group-order.tsrx
@@ -84,6 +84,19 @@
</>
}
+// A static sheet, then a setup-local-computed sheet, then another static sheet.
+// SSR must preserve source order across the partition boundary — the static
+// trailing sheet must NOT be reordered ahead of the setup-local one.
+export function MixedStaticAndLocal(props) @{
+ const slug = '/' + props.name + '-local.css';
+ <>
+ <link rel="stylesheet" href="/first-static.css" precedence="one" />
+ <link rel="stylesheet" href={slug} precedence="two" />
+ <link rel="stylesheet" href="/last-static.css" precedence="three" />
+ <div class="mixed">{'M'}</div>
+ </>
+}
+
function Exploding(props) @{
const boom = () => {
throw new Error('mount failure');
diff --git a/packages/octane/tests/float-resources.test.ts b/packages/octane/tests/float-resources.test.ts
--- a/packages/octane/tests/float-resources.test.ts
+++ b/packages/octane/tests/float-resources.test.ts
@@ -44,6 +44,7 @@
NestedTryOrder,
LocalHref,
FailingArm,
+ MixedStaticAndLocal,
} from './_fixtures/float-group-order.tsrx';
function sheetHrefs(): string[] {
@@ -613,6 +614,21 @@
expect(sheetHrefs()).toEqual(['/x-dep.css']);
});
+ it('SSR preserves source order when static and setup-local head hoists are mixed', async () => {
+ const App = () => Server.createElement(srvOrder.MixedStaticAndLocal, { name: 'x' }) as any;
+ const r = await Server.renderToString(App as any);
+ const first = r.html.indexOf('/first-static.css');
+ const local = r.html.indexOf('/x-local.css');
+ const last = r.html.indexOf('/last-static.css');
+ expect(first).toBeGreaterThan(-1);
+ expect(local).toBeGreaterThan(first);
+ expect(last).toBeGreaterThan(local);
+
+ // Client control: same discovery order.
+ await act(() => mountInto(MixedStaticAndLocal, { name: 'x' }));
+ expect(sheetHrefs()).toEqual(['/first-static.css', '/x-local.css', '/last-static.css']);
+ });
+
it('an arm that fails while rendering a child keeps its already-registered sheet', async () => {
// Resources are page-global and never removed; registration precedes
// child evaluation on the server too, so client and server agree that aYou can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit f0b5392. Configure here.
Registration order is precedence-group order, so the capture split must not reorder the list: a capture-free head statement after a capturing one used to jump to the body front, cascading differently on SSR than on a client mount. Only the capture-free prefix leads now; from the first capturing statement on, everything defers together in source order. (Bugbot review finding.) Co-Authored-By: Claude Fable 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
@tryarms at reveal — matching SSR and React. Previously groups formed in body-completion order, so a nested child's or arm's group could precede its parent's ([three, one, two]where SSR gives[one, two, three]).const slug = …; <link href={slug} precedence …>) emitted its registration ahead of the local's declaration — a TDZReferenceErrorat render. This affectedssrHeadElmetadata hoists too, not just resources.Closes the "adjudicate: client precedence group order under nested
@try" item in #711 — adjudicated as fix, since group order is CSS cascade order and Octane disagreed with its own SSR output.Why
Group order is decided by first registration (
insertPrecedencedappends new groups after the last one). The client emitted resource calls at the body tail (plan.head, after constructs), so children — which mount inside the parent's constructs — registered first. The server emits head statements at the body front, which is what ships arm-root sheets with the streaming shell, but is only evaluable when the statement reads nothing the body itself declares.Changes
packages/octane/src/compiler/compile.js(compiler-only; zero runtime changes, no new statements — the same calls move):emitHeadClientnow returns{head, resources}: scope-ownedheadBlockmetadata stays at the body tail (slot numbering untouched — resource slots were already left unoccupied); global resource calls (stylesheetResource/styleResource/scriptResource) land after setup, before the constructs mount children. Setup locals are initialized by then, and no child has rendered yet, so groups form in discovery order. A suspending setup means the arm's resource registers on its completing pass — like React's commit-time insertion.collectFreeIdentifiers/collectStatementBindingshelpers): capture-free statements keep the historical front placement — arm-root sheets still ship with the streaming shell (fix: ship Float sheet resources discovered after the streaming shell #727's pinned behavior) — while statements reading setup locals run right after setup, still ahead of thereturnthat renders children.Tests: 6 new cases in
float-resources.test.ts+_fixtures/float-group-order.tsrx(parent/child order, suspended-arm-at-reveal order, nested-arm waves, SSR order pin, setup-local href on both sides, failed-arm resource persistence). Doc: one clarifying sentence indifferences-from-react.md(first-encounter = tree discovery order, all sides agree).Red-first evidence
parent/childandarm-after-siblingfail with inverted group order;setup-local hreffails with the exact TDZ (Cannot access 'slug' before initialization) inrenderComponentFramed.nested @try across waves, SSR order) pass pre-fix and are kept as contract pins — stated so their green isn't mistaken for fix coverage.Performance
Compiler-only statement reordering: generated output has identical statement count and size, so no runtime benchmark applies. The compile-time addition is one free-identifier scan per head statement, only in bodies that hoist head elements, and only when the body declares bindings. No per-render, per-node, or bundle cost changes.
Adversarial self-review (what it changed)
ssrHeadElmetadata had the same TDZ hazard.vardeclared inside a nested setup block escapes the capture scan and keeps front placement (pre-existing behavior; head attrs read top-level setup locals in practice).Review round 1 (Bugbot, fixed in 088b0be)
Valid finding: the server partition preserved the front/deferred split but not source order between them — a capture-free head statement appearing after a capturing one still jumped to the body front, so mixed static and setup-local resources in one body could cascade differently on SSR than on a client mount. Fixed with a prefix rule: only the capture-free prefix of the head-statement list leads the body; from the first capturing statement on, everything defers together in source order — the exact sequence the client produces. Red-first:
MixedLocalStatic(setup-local sheet followed by a static sheet) asserted SSR order matched the client and failed before the rule ([static, dynamic] on SSR), passes after. The nested-pending-boundary shell test still passes: a capture-free arm-root sheet remains the list prefix, so it keeps shipping with the shell.Validation
pnpm format:files:check(changed files)pnpm typecheckpnpm test— 20,930 passed; the one failing file (doom-browser, 3 cases) is full-suite CPU-contention flake: 7/7 in isolation, and the same lane failed identically on unmodified main in an earlier session's gatefloat-resources48/48 (dev + prod projects),hydration/+float-evidence-{1,2,3}+resource-hints+streaming-ssr880/880,compiler/1,149/1,149,differential/304/304float-resources50/50 (dev + prod), neighbor sweep (hydration/,float-evidence-{1,2,3},resource-hints,streaming-ssr,compiler/) 2,029/2,029Risk / follow-ups
var-in-nested-block capture-scan bound above.Provenance
agent-authored)Note
Medium Risk
Compiler-only reordering changes CSS cascade group order on client mounts and when SSR runs head registration, affecting hydration parity for Float stylesheets; no runtime logic changes but behavior is user-visible.
Overview
Float precedence groups on client mounts now follow tree discovery order (parent before child,
@tryarms when they reveal), aligning client-only mounts with SSR and React. The compiler moves global resource calls (stylesheetResource/styleResource/scriptResource) to run after setup and before child constructs mount, instead of at the body tail withheadBlockmetadata.SSR head emission is split by capture-freeness: registrations that do not read setup locals still lead the body (streaming shell behavior); hoists whose attributes depend on setup locals (e.g.
<link href={slug} precedence …>) run after setup so they no longer hit a TDZReferenceError.Adds fixtures/tests for parent/child order, suspended arms, nested
@trywaves, SSR order, setup-local href, and failed-arm sheet retention; docs clarify first-encounter = discovery order.Reviewed by Cursor Bugbot for commit f0b5392. Bugbot is set up for automated code reviews on this repo. Configure here.