Repository navigation
fix(octane): improve Activity parity and batch hidden updates - #816
Merged
Merged
Conversation
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: 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.
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.
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
octanepatch 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
createElement(Activity, ...), spreads, children props, and authored key precedence. Preserve the direct mode-only compiler output and lazy hidden-child omission on the server.Full findings and reproduction commands:
docs/activity-audit.mdandbenchmarks/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.
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-localCOREPACK_ENABLE_NETWORK=0 pnpm_config_verify_deps_before_run=falseto avoid automatic reinstallation of borrowed dependency links; no generated tracked diff.git diff --check.tsgo, narrowed Activitytsrx-tsc, benchmarktsrx-tsc, and compiler syntax checks.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 lockedoxc-tsrxinstallation 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
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
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.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.