Skip to content

Commit 50b3207

Browse files
authored
fix(cdk/platform): avoid error during server-side rendering if document is stubbed out (#22260)
Fixes an error that can be thrown by the `supportsScrollBehavior` helper if the global `document` variable is stubbed out. Fixes #22259.
1 parent ee49922 commit 50b3207

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/cdk/platform/features/scrolling.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ let scrollBehaviorSupported: boolean|undefined;
3434
/** Check whether the browser supports scroll behaviors. */
3535
export function supportsScrollBehavior(): boolean {
3636
if (scrollBehaviorSupported == null) {
37-
// If we're not in the browser, it can't be supported.
38-
if (typeof document !== 'object' || !document) {
37+
// If we're not in the browser, it can't be supported. Also check for `Element`, because
38+
// some projects stub out the global `document` during SSR which can throw us off.
39+
if (typeof document !== 'object' || !document || typeof Element !== 'function' || !Element) {
3940
scrollBehaviorSupported = false;
4041
return scrollBehaviorSupported;
4142
}

0 commit comments

Comments
 (0)