Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/core/src/hydration/annotate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {assertTNode} from '../render3/assert';
import {collectNativeNodes, collectNativeNodesInLContainer} from '../render3/collect_native_nodes';
import {getComponentDef} from '../render3/definition';
import {CONTAINER_HEADER_OFFSET, LContainer} from '../render3/interfaces/container';
import {isTNodeShape, TNode, TNodeType} from '../render3/interfaces/node';
import {isLetDeclaration, isTNodeShape, TNode, TNodeType} from '../render3/interfaces/node';
import {RElement} from '../render3/interfaces/renderer_dom';
import {
hasI18n,
Expand Down Expand Up @@ -400,7 +400,7 @@ function serializeLView(lView: LView, context: HydrationContext): SerializedView
: null;
// Iterate over DOM element references in an LView.
for (let i = HEADER_OFFSET; i < tView.bindingStartIndex; i++) {
const tNode = tView.data[i] as TNode;
const tNode = tView.data[i];
const noOffsetIndex = i - HEADER_OFFSET;

// Attempt to serialize any i18n data for the given slot. We do this first, as i18n
Expand Down Expand Up @@ -526,8 +526,10 @@ function serializeLView(lView: LView, context: HydrationContext): SerializedView

ngh[CONTAINERS] ??= {};
ngh[CONTAINERS][noOffsetIndex] = serializeLContainer(lView[i], context);
} else if (Array.isArray(lView[i])) {
} else if (Array.isArray(lView[i]) && !isLetDeclaration(tNode)) {
// This is a component, annotate the host node with an `ngh` attribute.
// Note: Let declarations that return an array are also storing an array in the LView,
// we need to exclude them.
const targetNode = unwrapRNode(lView[i][HOST]!);
if (!(targetNode as HTMLElement).hasAttribute(SKIP_HYDRATION_ATTR_NAME)) {
annotateHostElementForHydration(targetNode as RElement, lView[i], context);
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/render3/interfaces/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ export function isTNodeShape(value: unknown): value is TNode {
);
}

export function isLetDeclaration(tNode: TNode): boolean {
return !!(tNode.type & TNodeType.LetDeclaration);
}

/**
* Corresponds to the TNode.flags property.
*/
Expand Down
31 changes: 31 additions & 0 deletions packages/platform-server/test/hydration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7917,6 +7917,37 @@ describe('platform-server hydration integration', () => {
verifyClientAndSSRContentsMatch(ssrContents, clientRootNode);
expect(clientRootNode.textContent).toContain('inside before|after');
});

it('should handle let declaration with array inside of an embedded view', async () => {
@Component({
standalone: true,
selector: 'app',
template: `
@let foo = ['foo'];
@if (true) {
{{foo}}
}
`,
})
class SimpleComponent {}

const html = await ssr(SimpleComponent);
const ssrContents = getAppContents(html);

expect(ssrContents).toContain('<app ngh');
expect(ssrContents).toContain('foo');

resetTViewsFor(SimpleComponent);

const appRef = await renderAndHydrate(doc, html, SimpleComponent);
const compRef = getComponentRef<SimpleComponent>(appRef);
appRef.tick();

const clientRootNode = compRef.location.nativeElement;
verifyAllNodesClaimedForHydration(clientRootNode);
verifyClientAndSSRContentsMatch(ssrContents, clientRootNode);
expect(clientRootNode.textContent).toContain('foo');
});
});

describe('Router', () => {
Expand Down