From 8c339a17c1f1eeb5a56f34cd8e25e4ef7f9bb2d7 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Wed, 1 Jan 2025 10:19:43 +0100 Subject: [PATCH] fix(cdk/scrolling): avoid SSR error in CdkVirtualScrollableWindow The `CdkVirtualScrollableWindow` was referring to the `document` directly which can break in SSR. These changes use the DI token instead. --- src/cdk/scrolling/virtual-scrollable-window.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cdk/scrolling/virtual-scrollable-window.ts b/src/cdk/scrolling/virtual-scrollable-window.ts index 3b6b805499b6..f7daf14f1d96 100644 --- a/src/cdk/scrolling/virtual-scrollable-window.ts +++ b/src/cdk/scrolling/virtual-scrollable-window.ts @@ -6,7 +6,8 @@ * found in the LICENSE file at https://angular.dev/license */ -import {Directive, ElementRef} from '@angular/core'; +import {Directive, ElementRef, inject} from '@angular/core'; +import {DOCUMENT} from '@angular/common'; import {CdkVirtualScrollable, VIRTUAL_SCROLLABLE} from './virtual-scrollable'; /** @@ -21,6 +22,7 @@ export class CdkVirtualScrollableWindow extends CdkVirtualScrollable { constructor() { super(); + const document = inject(DOCUMENT); this.elementRef = new ElementRef(document.documentElement); this._scrollElement = document; }