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
3 changes: 2 additions & 1 deletion packages/core/src/render3/view_manipulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export function getLViewFromLContainer<T>(lContainer: LContainer, index: number)
*/
export function shouldAddViewToDom(
tNode: TNode, dehydratedView?: DehydratedContainerView|null): boolean {
return !dehydratedView || hasInSkipHydrationBlockFlag(tNode);
return !dehydratedView || !dehydratedView.firstChild?.parentElement ||
hasInSkipHydrationBlockFlag(tNode);
}

export function addLViewToLContainer(
Expand Down
46 changes: 46 additions & 0 deletions packages/platform-server/test/hydration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6284,6 +6284,52 @@ describe('platform-server hydration integration', () => {
[4, 5].map(id => compRef.location.nativeElement.querySelector(`[id=${id}]`));
verifyAllNodesClaimedForHydration(clientRootNode, Array.from(clientRenderedItems));
});

it('should handle a reconciliation with swap', async () => {
@Component({
selector: 'app',
standalone: true,
template: `
@for(item of array2; track item) {
<div>{{ item }}</div>
}
`,
})
class SimpleComponent {
array2 = ['foo', 'bar', 'baz'];

swap() {
this.array2.sort();
}
}

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

expect(ssrContents).toContain(`<app ${NGH_ATTR_NAME}`);

resetTViewsFor(SimpleComponent);

expect(ssrContents).toContain('foo');
expect(ssrContents).toContain('bar');
expect(ssrContents).toContain('baz');

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

await whenStable(appRef);

const root: HTMLElement = compRef.location.nativeElement;
const divs = root.querySelectorAll(`div`);
expect(divs.length).toBe(3);

compRef.instance.swap();
compRef.changeDetectorRef.detectChanges();

const divsAfterSwap = root.querySelectorAll(`div`);
expect(divsAfterSwap.length).toBe(3);
});
});

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