Skip to content

Commit

Permalink
fix(cdk/scrolling): avoid SSR error in CdkVirtualScrollableWindow (#3…
Browse files Browse the repository at this point in the history
…0259)

The `CdkVirtualScrollableWindow` was referring to the `document` directly which can break in SSR. These changes use the DI token instead.
  • Loading branch information
crisbeto authored Jan 3, 2025
1 parent 4e04540 commit 5c75bbe
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/cdk/scrolling/virtual-scrollable-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -21,6 +22,7 @@ export class CdkVirtualScrollableWindow extends CdkVirtualScrollable {

constructor() {
super();
const document = inject(DOCUMENT);
this.elementRef = new ElementRef(document.documentElement);
this._scrollElement = document;
}
Expand Down

0 comments on commit 5c75bbe

Please sign in to comment.