Skip to content

Commit

Permalink
fix(cdk/scrolling): error during server-side rendering (#25461)
Browse files Browse the repository at this point in the history
Fixes that an error was being thrown by the virtual scroller during server-side rendering. It wasn't failing the SSR check, because the error happens inside of a promise callback.

(cherry picked from commit d9e96ff)
  • Loading branch information
crisbeto authored and amysorto committed Aug 23, 2022
1 parent 7021d31 commit 7e807aa
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/cdk/scrolling/virtual-scroll-viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ChangeDetectorRef,
Component,
ElementRef,
inject,
Inject,
Input,
NgZone,
Expand All @@ -23,6 +24,7 @@ import {
ViewChild,
ViewEncapsulation,
} from '@angular/core';
import {Platform} from '@angular/cdk/platform';
import {
animationFrameScheduler,
asapScheduler,
Expand Down Expand Up @@ -77,6 +79,8 @@ const SCROLL_SCHEDULER =
],
})
export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements OnInit, OnDestroy {
private _platform = inject(Platform);

/** Emits when the viewport is detached from a CdkVirtualForOf. */
private readonly _detachedSubject = new Subject<void>();

Expand Down Expand Up @@ -205,6 +209,11 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
}

override ngOnInit() {
// Scrolling depends on the element dimensions which we can't get during SSR.
if (!this._platform.isBrowser) {
return;
}

if (this.scrollable === this) {
super.ngOnInit();
}
Expand Down

0 comments on commit 7e807aa

Please sign in to comment.