Skip to content

fix(octane): improve Activity parity and batch hidden updates - #816

Merged
trueadm merged 2 commits into
mainfrom
codex/activity-parity-performance-pr
Aug 21, 2026
Merged

trueadm merged 2 commits into
mainfrom
codex/activity-parity-performance-pr

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Correct observable Activity behavior across the DOM and universal runtimes, compiler authoring forms, SSR, hydration, and ViewTransition integration.
  • Batch hidden descendant visibility work once per render wave, removing a quadratic range scan.
  • Add a same-source production React/Octane benchmark suite, 32 deterministic regression guards, focused conformance coverage, an audit report, and an octane patch changeset.

Why

The initial new DOM suite failed all 26 development/production cases on the original runtime: hidden refs remained attached, authored display/text could restore stale values, deep portals remained visible, and hidden suspension activated an enclosing visible fallback. The benchmark independently measured 256 full range scans and 65,536 display checks for one batch of 256 hidden row updates.

Changes

  • Disconnect/reconnect the current public host and Fragment refs across Activity visibility, including cleanup-bearing callbacks, ref changes while hidden, nested ownership, teardown errors, and reentrancy.
  • Preserve the latest authored display/text under overlapping Activity/Suspense hides; track logical portal ownership and newly inserted or retried portal content.
  • Contain hidden suspension, retain pending state, and replay insertion effects safely through memo/cached-child bailouts, repeated custom-hook enqueues, superseding/omitted hooks, and nested Activity ownership. Keep render-loop guards active during retries.
  • Support aliases, namespaces, dynamic tags, createElement(Activity, ...), spreads, children props, and authored key precedence. Preserve the direct mode-only compiler output and lazy hidden-child omission on the server.
  • Correct ViewTransition enter/exit classification for both nesting orders and expose native pseudo-element animations through the public transition instance.
  • Keep optional Activity descriptor dispatch tree-shakeable; gate ref manifests and insertion snapshots, cache negative ref ownership, and disable ref tracking after the last Activity unmounts.

Full findings and reproduction commands: docs/activity-audit.md and benchmarks/activity/README.md.

Performance

Same-machine, same-toolchain production browser measurements; the repeat ran in reverse order with 16 samples. These are benchmark steady-window scores, not full-sample means.

Measurement Original Candidate
256 hidden descendant updates, completed work 9.271 ms 0.286 ms (~32x faster)
Range scans / display checks for that batch 256 / 65,536 1 / 256
Eight hide/reveal cycles 2.957 ms 4.300 ms (+45%)
Eight nested visibility cycles 5.786 ms 7.671 ms (+33%)
Twelve plain-tree prop updates 1.729 ms 1.943 ms (+12%; no added named Activity helper work)

All state writes and retained identities are verified. Hidden setter batches add no style writes or row churn; both toggle workloads retain the original 4,096 style writes. Ordinary ref controls pass before, after, and alongside a separate hidden Activity. The five ordinary bundle controls exclude the optional Activity implementation, but shared correctness changes add 311–538 gzip bytes. Direct Activity/ref-control compiler outputs remain byte-identical.

The 32 guards protect deterministic work, DOM retention, cold paths, and optional implementation reachability. The original baseline fails exactly the three quadratic-work guards; the candidate passes all 32. No wall-clock ceiling was introduced and no existing absolute bundle-size budget was loosened.

Validation

  • pnpm run sync — passed with process-local COREPACK_ENABLE_NETWORK=0 pnpm_config_verify_deps_before_run=false to avoid automatic reinstallation of borrowed dependency links; no generated tracked diff.
  • Scoped Prettier over all changed/new files and git diff --check.
  • Final focused Activity/compiler/SSR/hydration/Fragment/Suspense/ViewTransition/conditional-hook run: 971 tests across 57 files, development and production where configured; rerun on the clean PR branch.
  • Universal neighboring suites: 652 tests across 34 files.
  • Native Chromium Activity/ViewTransition: 4 cases, both nesting orders and both compiler modes, including native animation handles and retained edited input.
  • Strict core tsgo, narrowed Activity tsrx-tsc, benchmark tsrx-tsc, and compiler syntax checks.
  • Unified Activity benchmark: 32/32 guards; shared precise-work tests: 6/6.
  • pnpm format:check — repository-wide command not run; scoped check passed.
  • pnpm typecheck — normal full-workspace gate not established; real dependency declaration overlays were used for the strict/scoped checks. The broader changed-file graph retains pre-existing universal-object and ViewTransition fixture typing diagnostics.
  • pnpm test — normal native-parser/full-workspace gate not established. The locked oxc-tsrx installation returned HTTP 403, so the audit used the supported JavaScript parser adapter and explicit worktree aliases.

The broad core run plus corrected root-equivalent differential/profile/language-service cohorts accounts for 13,639 passed assertions across 861 file executions. Six environment-failed executions/eight assertions remain for the unavailable native parser or incomplete installed workspace-package layout. Frozen/candidate controls agree; this aggregate is not a single green full-suite invocation. No fake packages, ambient TSRX modules, manifest changes, or lockfile changes were used.

Risk / follow-ups

  • This is not a claim of complete React parity or universal performance improvement. Toggle workloads are slower, and shared bundle bytes increase as recorded above.
  • General atomic deletion during a suspended hidden render remains the existing per-swap structural-transaction limitation. Queue rollback cannot undo an already-executed unmount cleanup; a general fix requires owner-state staging across branch, descriptor, key/component, list, and portal mutations.
  • Synchronous hidden work, no React offscreen/idle lane, and no selective-hydration scheduling remain intentional differences.
  • Repeat the normal native-parser, full-workspace, and authoritative bundle-budget gates in a complete installation before readiness. Audit timings used Node 26.4.0, Chromium 149, React 19.2.7, Vite 8.1.5, esbuild 0.28.1, and the same supported JS-parser fallback for both revisions.
  • The PR is isolated onto public upstream baseline 2d2f638b5da4ccb9a5ec46c5cea7b9c52c059192. Its runtime/compiler, package manifest, and lockfile match the local merge used for the audit; three unrelated inherited test/changeset files are excluded. Integrate the live base and repeat required checks before marking ready.

Provenance

  • An agent produced this diff (agent-authored)

Note

High Risk
Touches core Activity commit, refs, Suspense containment, compiler lowering, and SSR/hydration. Visibility and identity bugs here can leak hidden UI or drop retained state.

Overview
Fixes observable <Activity> behavior so hide/reveal matches the intended React contract: disconnect/reconnect public refs, restore latest authored display/text, hide logically owned portals, and keep hidden suspension from activating a visible outer fallback. Insertion effects now replay safely after suspended hidden renders (including memoized children and nested boundaries).

Coalesces hidden descendant visibility into one range scan per render wave (256 scans / 65,536 display checks → 1 / 256 for a 256-row setter batch). Optional Activity implementation and ref tracking stay off ordinary trees; hide/reveal itself is slower.

Compiler still uses the direct mode-only fast path, but aliases, namespaces, spreads, children props, and ordered keys now resolve to the same boundary. SSR/hydration omit hidden children; ViewTransition enter/exit covers both nesting orders.

Adds a same-source Octane/React production benchmark, 32 deterministic work/ref/bundle guards, and docs/activity-audit.md. Synchronous hidden scheduling and the existing per-swap structural-deletion limit are unchanged.

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


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Aug 21, 2026

@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: Server misses Activity block need
    • serverDescNeedsBlocks now treats the Activity sentinel like Fragment, so a deopt host whose Activity child wraps only hosts/text serializes child-slot markers that hydration can adopt.

Create PR

Or push these changes by commenting:

@cursor push 93d47a53f4
Preview (93d47a53f4)
diff --git a/packages/octane/src/runtime.server.ts b/packages/octane/src/runtime.server.ts
--- a/packages/octane/src/runtime.server.ts
+++ b/packages/octane/src/runtime.server.ts
@@ -1606,9 +1606,9 @@ function serverDescNeedsBlocks(v: unknown): boolean {
 	if (!isElementDescriptor(v) && childrenIterator(v) !== null) return true;
 	const d = v as ElementDescriptor;
 	if (d.$$kind === ELEMENT_TAG) {
-		// A Fragment below a host descriptor is reconciled by childSlot's
-		// fragment-aware list path, including when all of its leaves are pure hosts.
-		if (d.type === Fragment) return true;
+		// Fragment and Activity are sentinel symbols, not functions. Both still
+		// own a childSlot range, including when all of their leaves are pure hosts.
+		if (d.type === Fragment || d.type === Activity) return true;
 		return typeof d.type === 'function' || serverDescNeedsBlocks(d.children);
 	}
 	return false;

@@ -1606,9 +1606,9 @@ function serverDescNeedsBlocks(v: unknown): boolean {
 	if (!isElementDescriptor(v) && childrenIterator(v) !== null) return true;
 	const d = v as ElementDescriptor;
 	if (d.$$kind === ELEMENT_TAG) {
-		// A Fragment below a host descriptor is reconciled by childSlot's
-		// fragment-aware list path, including when all of its leaves are pure hosts.
-		if (d.type === Fragment) return true;
+		// Fragment and Activity are sentinel symbols, not functions. Both still
+		// own a childSlot range, including when all of their leaves are pure hosts.
+		if (d.type === Fragment || d.type === Activity) return true;
 		return typeof d.type === 'function' || serverDescNeedsBlocks(d.children);
 	}
 	return false;

diff --git a/packages/octane/tests/activity-authoring.test.ts b/packages/octane/tests/activity-authoring.test.ts
--- a/packages/octane/tests/activity-authoring.test.ts
+++ b/packages/octane/tests/activity-authoring.test.ts
@@ -573,4 +573,52 @@ describe('<Activity> server rendering and hydration', () => {
 		expect(button.style.display).toBe('');
 		expect(host.querySelector('#descriptor-tail')).toBe(tail);
 	});
+
+	it('adopts a deopt host whose Activity child wraps only hosts', () => {
+		function serverApp() {
+			return Server.createElement(
+				'section',
+				null,
+				Server.createElement(
+					Server.Activity,
+					{ mode: 'visible' },
+					Server.createElement('span', { id: 'activity-host-child' }, 'hello'),
+				),
+				Server.createElement('i', { id: 'descriptor-tail' }, 'tail'),
+			);
+		}
+		function clientApp(props: { mode: 'visible' | 'hidden' }) {
+			return createElement(
+				'section',
+				null,
+				createElement(
+					Activity,
+					{ mode: props.mode },
+					createElement('span', { id: 'activity-host-child' }, 'hello'),
+				),
+				createElement('i', { id: 'descriptor-tail' }, 'tail'),
+			);
+		}
+		const host = container();
+		host.innerHTML = Server.renderToString(serverApp).html;
+		const span = host.querySelector('#activity-host-child');
+		const tail = host.querySelector('#descriptor-tail');
+		expect(span).not.toBeNull();
+		expect(tail).not.toBeNull();
+		const root = hydrateRoot(host, clientApp, { mode: 'visible' });
+		roots.push(root);
+		flushSync(() => {});
+		expect(host.querySelector('#activity-host-child')).toBe(span);
+		expect(host.querySelector('#descriptor-tail')).toBe(tail);
+		root.render(clientApp, { mode: 'hidden' });
+		flushSync(() => {});
+		expect(host.querySelector('#activity-host-child')).toBe(span);
+		expect((span as HTMLElement).style.display).toBe('none');
+		expect(host.querySelector('#descriptor-tail')).toBe(tail);
+		root.render(clientApp, { mode: 'visible' });
+		flushSync(() => {});
+		expect(host.querySelector('#activity-host-child')).toBe(span);
+		expect((span as HTMLElement).style.display).toBe('');
+		expect(host.querySelector('#descriptor-tail')).toBe(tail);
+	});
 });

@@ -573,4 +573,52 @@ describe('<Activity> server rendering and hydration', () => {
 		expect(button.style.display).toBe('');
 		expect(host.querySelector('#descriptor-tail')).toBe(tail);
 	});
+
+	it('adopts a deopt host whose Activity child wraps only hosts', () => {
+		function serverApp() {
+			return Server.createElement(
+				'section',
+				null,
+				Server.createElement(
+					Server.Activity,
+					{ mode: 'visible' },
+					Server.createElement('span', { id: 'activity-host-child' }, 'hello'),
+				),
+				Server.createElement('i', { id: 'descriptor-tail' }, 'tail'),
+			);
+		}
+		function clientApp(props: { mode: 'visible' | 'hidden' }) {
+			return createElement(
+				'section',
+				null,
+				createElement(
+					Activity,
+					{ mode: props.mode },
+					createElement('span', { id: 'activity-host-child' }, 'hello'),
+				),
+				createElement('i', { id: 'descriptor-tail' }, 'tail'),
+			);
+		}
+		const host = container();
+		host.innerHTML = Server.renderToString(serverApp).html;
+		const span = host.querySelector('#activity-host-child');
+		const tail = host.querySelector('#descriptor-tail');
+		expect(span).not.toBeNull();
+		expect(tail).not.toBeNull();
+		const root = hydrateRoot(host, clientApp, { mode: 'visible' });
+		roots.push(root);
+		flushSync(() => {});
+		expect(host.querySelector('#activity-host-child')).toBe(span);
+		expect(host.querySelector('#descriptor-tail')).toBe(tail);
+		root.render(clientApp, { mode: 'hidden' });
+		flushSync(() => {});
+		expect(host.querySelector('#activity-host-child')).toBe(span);
+		expect((span as HTMLElement).style.display).toBe('none');
+		expect(host.querySelector('#descriptor-tail')).toBe(tail);
+		root.render(clientApp, { mode: 'visible' });
+		flushSync(() => {});
+		expect(host.querySelector('#activity-host-child')).toBe(span);
+		expect((span as HTMLElement).style.display).toBe('');
+		expect(host.querySelector('#descriptor-tail')).toBe(tail);
+	});
 });

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

Reviewed by Cursor Bugbot for commit 110e925. Configure here.

Comment thread packages/octane/src/runtime.server.ts Resolved
@trueadm
trueadm marked this pull request as ready for review August 21, 2026 11:29
@trueadm
trueadm merged commit 4b590bd into main Aug 21, 2026
41 of 48 checks passed
@trueadm
trueadm deleted the codex/activity-parity-performance-pr branch August 21, 2026 11:38
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