Skip to content
Open
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
7 changes: 7 additions & 0 deletions packages/core/src/hydration/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
DEHYDRATED_VIEWS,
LContainer,
} from '../render3/interfaces/container';
import {isLetDeclaration, TNode} from '../render3/interfaces/node';
import {Renderer} from '../render3/interfaces/renderer';
import {RNode} from '../render3/interfaces/renderer_dom';
import {isLContainer, isLView} from '../render3/interfaces/type_checks';
Expand Down Expand Up @@ -113,6 +114,12 @@ export function cleanupLView(lView: LView) {

const tView = lView[TVIEW];
for (let i = HEADER_OFFSET; i < tView.bindingStartIndex; i++) {
// Let declarations store their value directly in the LView, which can look like an LView.
const tNode = tView.data[i] as TNode | null;
if (tNode && isLetDeclaration(tNode)) {
continue;
}

if (isLContainer(lView[i])) {
const lContainer = lView[i];
cleanupLContainer(lContainer);
Expand Down
36 changes: 36 additions & 0 deletions packages/platform-server/test/full_app_hydration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8323,6 +8323,42 @@ describe('platform-server full application hydration integration', () => {
verifyClientAndSSRContentsMatch(ssrContents, clientRootNode);
expect(clientRootNode.textContent).toContain('Main: Slot: 2');
});

it('should not modify an array stored in a let declaration during cleanup', async () => {
@Component({
selector: 'app',
template: `
@let list = items;
@if (true) {
Length: {{ list.length }}
}
`,
})
class SimpleComponent {
items = Array.from({length: 8}, (_, i) => ({id: i}));
}

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

expect(ssrContents).toContain('<app ngh');
expect(ssrContents).toContain('Length: 8');

resetTViewsFor(SimpleComponent);

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

const clientRootNode = compRef.location.nativeElement;
verifyAllNodesClaimedForHydration(clientRootNode);
verifyClientAndSSRContentsMatch(ssrContents, clientRootNode);
expect(clientRootNode.textContent).toContain('Length: 8');

await appRef.whenStable();

expect(Object.keys(compRef.instance.items[6])).toEqual(['id']);
});
});

describe('@boundary', () => {
Expand Down
Loading