Skip to content

feat: React 19 parity tranche — Float resources, root error callbacks, module hints, parity dispositions - #709

Merged
trueadm merged 3 commits into
mainfrom
feat/react19-parity-tranche
Aug 11, 2026
Merged

trueadm merged 3 commits into
mainfrom
feat/react19-parity-tranche

Conversation

@trueadm

@trueadm trueadm commented Aug 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Implements the React Float resource model: <link rel="stylesheet" href precedence> and <script async src> at a component's body root are now global resources — hoisted to document.head, deduped by href/src, stylesheet groups ordered by precedence (first-encounter group order, appended within a group), retained after unmount, emitted in buffered AND streamed SSR head output, and hydration-deduped (the first client call seeds from SSR-emitted data-precedence/data-oct-res tags).
  • Adds preloadModule/preinitModule to the resource hints on both octane and octane/server.
  • Adds React 19's root error-callback options to createRoot/hydrateRoot: onCaughtError (boundary claimed an error from the render/passive-effect/ref-attach channel), onUncaughtError (replaces the default report — the flush rethrow / effect-channel console.error — while the failed root's tree still unmounts), and onRecoverableError (structural hydration recovery, dev AND prod, coalesced per root per microtask burst). Error-only signature; no errorInfo/componentStack.
  • Aliases unstable_Activity → Activity (client + server + compiler tag whitelist), mirroring unstable_ViewTransition.
  • Records the partial pre-rendering (resume/postpone) and cache()/cacheSignal() decisions as documented non-goals in the conformance ledger (27 entries flipped from planned), regenerates docs/react-parity-coverage.md, fixes the stale octane/static comment, and documents hydrateRoot's missing formState option as an RSC-adjacent non-goal.
  • Doc sweep: docs/differences-from-react.md now covers the previously undocumented divergences — Context.Consumer absence, <title> child concatenation, per-compile-site metadata dedupe, hidden-<Activity> scheduling (no offscreen lane), dropped stream options (progressiveChunkSize, namespaceURI), prerender's {html, css} shape vs React's {prelude}, the useId format, the version string caveat, captureOwnerStack/unstable_batchedUpdates/gesture-VT non-goals, and the doctype wording fix. docs/ssr.md and docs/view-transitions.md gain matching entries.

Why

A deep React 19.2 parity audit (4 parallel area audits over the runtime, react-dom statics, SSR surface, and 19.1/19.2 additions) found the Float resource model was the largest functional gap (ReactDOMFloat-test.js is the single largest planned block in the ledger at 131 cases), the root error callbacks were absent and undocumented, partial pre-rendering had contradictory ledger dispositions (32 non-goal vs 19 planned), and roughly a dozen real divergences existed in code but not in differences-from-react.md, which promises "parity outside the documented differences".

Changes

  • packages/octane/src/runtime.ts — Float resource insertion (stylesheetResource/scriptResource, DOM-seeded dedupe state, tier-3 resetFloatResourceState), preloadModule/preinitModule, RootOptions error callbacks + ROOT_ERROR_HANDLERS WeakMap (off the Block shape), caught/uncaught report wiring at the boundary-claim and default-report sites, noteRecoverableHydrationError at the structural hydration-recovery sites, unstable_Activity alias.
  • packages/octane/src/runtime.server.ts — ssrStylesheetResource/ssrScriptResource, HeadBuffer.sheets precedence grouping (participates in both suspense-replay snapshot/rewind sites), head fold via headHtmlWithSheets, server module hints.
  • packages/octane/src/compiler/compile.js — headResourceKind static classifier (link+rel=stylesheet+href+precedence; script+async+src, async={false} excluded, no handlers/children), script admission into the HeadHoist partition, emitter routing to the resource ABI (headBlock slot numbering unchanged), unstable_Activity in the builtin-import whitelist and isActivityLongForm.
  • packages/octane/src/{index,server/index,static/index}.ts — exports and the corrected octane/static doc comment.
  • packages/octane/audit/react-conformance-ledger.json + docs/react-parity-coverage.md — 27 dispositions (FizzStatic postpone/resume → non-goal with the established rationale; ReactCache cache()/cacheSignal → non-goal) and the regenerated report.
  • Docs: differences-from-react.md, ssr.md, view-transitions.md.
  • Tests: tests/float-resources.test.ts (+fixture), tests/root-error-callbacks.test.ts (+fixture), tests/hydration/recoverable-callback.test.ts, module-hint cases in tests/resource-hints.test.ts, unstable_Activity case in tests/activity.test.ts (+fixture).

Contract and hot paths

Every new behavior is pay-per-use and off the hot paths: error-callback lookups run only on already-cold error/recovery paths behind a module-null check, handlers live in a WeakMap so the monomorphic Block shape is untouched, resource calls run once per authored resource element per render (dedupe-set hit after the first), and the compiler classifier adds two string compares per JSX child at compile time. No per-render/per-node work is added for components that use none of these features; no benchmark deltas are claimed and none are expected — the compiled output of code not using these features is byte-identical (head slot numbering deliberately preserved).

Known intentional bounds (documented in the diff): suspensey commits and <style href precedence> are non-goals; resource classification is static (spreads keep the element path); deletion-phase teardown errors keep their existing default report; onRecoverableError does not fire for attribute-level value patches (prod React cannot detect those at all).

Validation

  • pnpm format:check
  • pnpm typecheck
  • pnpm test — 18,480/18,481 passed. The one failure was a 20s timeout in packages/phosphor-icons/tests/differential/parity.test.ts under full-suite load; it passes in isolation in ~4s, passed in the previous full run with this same diff, and touches none of the changed code paths — reported here rather than papered over.
  • targeted tests: float-resources (14), root-error-callbacks (18), recoverable-callback (10), resource-hints (16), activity.test (73), packed-consumer/production-error-bundle (13, exercises the error-code audit that gated the new catalog codes), plus neighbor sweeps over boundary/mismatch/error-handling/streaming/head-hydrate/ssr-suspense suites — all green in dev and prod compile projects.
  • node scripts/react-parity/check.mjs --validate-only — ledger valid; coverage report verified byte-identical to renderCoverageReport over the committed inventories + edited ledger.
  • pnpm sync — committed generated changes (CLI data, error-code modules).
  • New tests were observed failing before their implementations landed (16 pre-fix failures for the error callbacks; the Float suite failed at compile/classification before the compiler change). The error-code audit itself caught the first implementation's plain-string new Error messages — the recoverable-error reports now use catalog codes 51–56 (minified in production, exactly like the rest of the framework's production errors).
  • Review-fix commit 781a667 (both Bugbot findings, reproduced with failing tests first): the synchronous first root.render() and hydrateRoot's unowned render-throw path now consume through onUncaughtError like the scheduled flush, and requiresTemplateNormalization admits <script async src> so return-position trees classify resources. Full suite re-run: 18,490/18,491 (same phosphor-icons load-timeout flake, passes in isolation; spun off as a separate task), targeted + owned-path/hydration sweeps (1,840 tests) green, pnpm sync clean.
  • Review-fix commit bb51576 (delegation finding, reproduced with a failing click-through test): a consumed unowned hydration failure now keeps the container's delegation registration and claim (real ownerToken passed through; the hosted-island path's full release is unchanged). Full suite re-run: 18,492/18,493 (same phosphor flake), react-hosted/hydration/boundary sweep (1,204 tests) green.

Risk / follow-ups

  • The universal renderer keeps its own root implementation: the new root error-callback options are DOM-runtime only for now (universal compile shares none of the head machinery — verified no exposure).
  • Streamed boundaries that discover resources after the shell follow the existing documented head divergence (client re-creates during hydration).
  • The ledger's Float cases remain planned: flipping them to covered requires exact-title conformance ports, which can now be written against the implemented behavior.
  • prerenderToNodeStream remains planned (comment now says so accurately).

Provenance

  • An agent produced this diff (agent-authored)

Note

Medium Risk
Touches error-reporting and hydration-recovery paths plus SSR head emission, but changes are pay-per-use, off the hot path, and covered by targeted tests. Defaults without the new options remain unchanged.

Overview
Closes a major React 19 parity gap by treating body-root <link rel="stylesheet" href precedence> and <script async src> as Float resources: hoisted into document.head, deduped by href/src, precedence-grouped, retained after unmount, and emitted in buffered/streamed SSR (with client hydration seeding).

createRoot/hydrateRoot gain React 19's onCaughtError, onUncaughtError, and onRecoverableError options (error-only; no errorInfo). Providing them changes reporting only — recovery/unmount semantics stay the same. Also adds preloadModule/preinitModule and aliases unstable_Activity → Activity.

Records partial pre-rendering, cache()/cacheSignal(), and formState as ledger non-goals, and documents previously missing divergences (Context.Consumer, title/metadata ownership, Activity scheduling, stream options, useId/version). Structural hydration recoveries now report via catalog codes 51–56.

Reviewed by Cursor Bugbot for commit bb51576. Bugbot is set up for automated code reviews on this repo. Configure here.

…, module hints, parity dispositions

Implements the React Float resource model (stylesheet precedence links and
async script hoisting with SSR + hydration dedupe), preloadModule/preinitModule,
the createRoot/hydrateRoot onCaughtError/onUncaughtError/onRecoverableError
options (error codes 51-56 for the recoverable channel), and the
unstable_Activity alias. Records partial pre-rendering and cache()/cacheSignal
as documented ledger non-goals and documents the previously unlisted
divergences in differences-from-react.md.

Co-Authored-By: Claude Fable 5 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent feat PR: new feature or capability labels Aug 11, 2026
Comment thread packages/octane/src/runtime.ts Resolved
Comment thread packages/octane/src/compiler/compile.js Resolved
…y return-position script resources

The synchronous first root.render() and hydrateRoot's unowned render-throw
path now consume the report through onUncaughtError exactly like the
scheduled-flush path (the failed tree is still discarded and the root stays
reusable), and requiresTemplateNormalization admits <script async src> so
value-position (return <jsx>) trees reach the Float resource partition.
Addresses both Bugbot findings on #709.

Co-Authored-By: Claude Fable 5 <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Hydration recovery drops event delegation
    • After releaseFailedHydration in the unowned onUncaughtError path, added claimRootContainer and registerDelegationTarget calls and passed the recovered token to makeRoot so the returned reusable root retains working delegated events and correct ownership tracking.

Create PR

Or push these changes by commenting:

@cursor push 5cd61e66b4
Preview (5cd61e66b4)
diff --git a/packages/octane/src/runtime.ts b/packages/octane/src/runtime.ts
--- a/packages/octane/src/runtime.ts
+++ b/packages/octane/src/runtime.ts
@@ -27499,7 +27499,8 @@
 		// retry client-remounts). Unowned hydration failures keep their existing
 		// behavior and rethrow untouched — unless this root's onUncaughtError
 		// consumes the report, which changes only the reporting: the failed
-		// adoption is released identically and the caller gets a reusable root.
+		// tree is torn down and the caller gets a reusable root with delegation
+		// and container ownership restored.
 		const releaseFailedHydration = (): void => {
 			DOM_ROOT_DISPOSERS.delete(rootBlock);
 			unmountBlock(rootBlock, false);
@@ -27515,7 +27516,21 @@
 		if (rendererRegionOwnerForBlock(rootBlock) === null) {
 			if (!reportUncaughtError(rootBlock, error)) throw error;
 			releaseFailedHydration();
-			return makeRoot(container, null, null, null, idState, renderReturnedValue, null, rootOptions);
+			// The recovered root is the caller's live handle — re-register
+			// delegation and reclaim the container so later .render() calls
+			// retain working delegated events and correct ownership tracking.
+			const recoveredToken = claimRootContainer(container);
+			registerDelegationTarget(container);
+			return makeRoot(
+				container,
+				null,
+				null,
+				null,
+				idState,
+				renderReturnedValue,
+				recoveredToken,
+				rootOptions,
+			);
 		}
 		try {
 			handleRenderError(rootBlock, error);

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 781a667. Configure here.

Comment thread packages/octane/src/runtime.ts Resolved
@cursor

cursor Bot commented Aug 11, 2026

Copy link
Copy Markdown

Bugbot Autofix prepared fixes for both issues found in the latest run.

  • ✅ Fixed: First render skips onUncaughtError
    • Added a reportUncaughtError call in the sync first-render catch block so that when handleRenderError throws, the root's onUncaughtError callback is consulted before rethrowing, matching the scheduled flush path's behavior.
  • ✅ Fixed: Script resources miss return JSX
    • Added a headResourceKind(node) !== null check in requiresTemplateNormalization so that return-position <script async src> elements trigger template normalization and reach the HeadHoist path that normalizeChildren already admits.

Create PR

Or push these changes by commenting:

@cursor push 9abdd844bb
Preview (9abdd844bb)
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
@@ -16316,6 +16316,7 @@
 		(tag !== 'link' || isHoistableHeadElementNode(node))
 	)
 		return true;
+	if (selfNs !== 'svg' && headResourceKind(node) !== null) return true;
 
 	const childNs =
 		typeof tag === 'string' && !isComponentTag(node) ? nsForChildren(tag, parentNs) : parentNs;

diff --git a/packages/octane/src/runtime.ts b/packages/octane/src/runtime.ts
--- a/packages/octane/src/runtime.ts
+++ b/packages/octane/src/runtime.ts
@@ -27228,6 +27228,7 @@
 					// later recovery render. In particular, effects registered before the
 					// throw belong to an aborted render and must never reach a later flush.
 					if (!mountedRoot.disposed) unmountBlock(mountedRoot);
+					if (reportUncaughtError(mountedRoot, unhandled)) return;
 					throw unhandled;
 				}
 				root.unmount();

You can send follow-ups to the cloud agent here.

@trueadm

trueadm commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator Author

@cursor push 9abdd84

@cursor

cursor Bot commented Aug 11, 2026

Copy link
Copy Markdown

Could not push Autofix changes. The PR branch has conflicting changes.

…n failure

When onUncaughtError consumes an unowned hydrateRoot render error, the
returned root is rendered into directly — there is no host retry to
re-register the container. Discard the failed adoption like createRoot's
sync-mount failure (unmount + clear) but keep the delegation registration
and container claim, passing the real ownerToken through so unmount()
releases both exactly once. The owned hosted-island path keeps its full
release. Click-through regression tests pin delegated events on recovered
roots for both paths.

Co-Authored-By: Claude Fable 5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review August 11, 2026 21:54
@trueadm
trueadm merged commit a03ff0f into main Aug 11, 2026
52 checks passed
@trueadm
trueadm deleted the feat/react19-parity-tranche branch August 11, 2026 22:03
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 feat PR: new feature or capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant