Skip to content

Commit 93d47a5

Browse files
committed
fix(octane): treat Activity as block-bearing on the server
Activity is a sentinel symbol, so serverDescNeedsBlocks never matched typeof type === 'function'. A deopt host whose child is an Activity wrapping only hosts/text then omitted child-slot markers that the hydrating client expects.
1 parent 110e925 commit 93d47a5

2 files changed

Lines changed: 51 additions & 3 deletions

File tree

‎packages/octane/src/runtime.server.ts‎

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

‎packages/octane/tests/activity-authoring.test.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,4 +573,52 @@ describe('<Activity> server rendering and hydration', () => {
573573
expect(button.style.display).toBe('');
574574
expect(host.querySelector('#descriptor-tail')).toBe(tail);
575575
});
576+
577+
it('adopts a deopt host whose Activity child wraps only hosts', () => {
578+
function serverApp() {
579+
return Server.createElement(
580+
'section',
581+
null,
582+
Server.createElement(
583+
Server.Activity,
584+
{ mode: 'visible' },
585+
Server.createElement('span', { id: 'activity-host-child' }, 'hello'),
586+
),
587+
Server.createElement('i', { id: 'descriptor-tail' }, 'tail'),
588+
);
589+
}
590+
function clientApp(props: { mode: 'visible' | 'hidden' }) {
591+
return createElement(
592+
'section',
593+
null,
594+
createElement(
595+
Activity,
596+
{ mode: props.mode },
597+
createElement('span', { id: 'activity-host-child' }, 'hello'),
598+
),
599+
createElement('i', { id: 'descriptor-tail' }, 'tail'),
600+
);
601+
}
602+
const host = container();
603+
host.innerHTML = Server.renderToString(serverApp).html;
604+
const span = host.querySelector('#activity-host-child');
605+
const tail = host.querySelector('#descriptor-tail');
606+
expect(span).not.toBeNull();
607+
expect(tail).not.toBeNull();
608+
const root = hydrateRoot(host, clientApp, { mode: 'visible' });
609+
roots.push(root);
610+
flushSync(() => {});
611+
expect(host.querySelector('#activity-host-child')).toBe(span);
612+
expect(host.querySelector('#descriptor-tail')).toBe(tail);
613+
root.render(clientApp, { mode: 'hidden' });
614+
flushSync(() => {});
615+
expect(host.querySelector('#activity-host-child')).toBe(span);
616+
expect((span as HTMLElement).style.display).toBe('none');
617+
expect(host.querySelector('#descriptor-tail')).toBe(tail);
618+
root.render(clientApp, { mode: 'visible' });
619+
flushSync(() => {});
620+
expect(host.querySelector('#activity-host-child')).toBe(span);
621+
expect((span as HTMLElement).style.display).toBe('');
622+
expect(host.querySelector('#descriptor-tail')).toBe(tail);
623+
});
576624
});

0 commit comments

Comments
 (0)