Skip to content

Commit

Permalink
fix(@nguniversal/common): add Window stubs to Engine (Clover)
Browse files Browse the repository at this point in the history
Closes #2108
  • Loading branch information
alan-agius4 committed May 20, 2021
1 parent e978c28 commit 635d61e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modules/common/clover/server/src/server-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as path from 'path';
import { URL } from 'url';
import { CustomResourceLoader } from './custom-resource-loader';
import { InlineCriticalCssProcessor } from './inline-css-processor';
import { augmentWindowWithStubs } from './stubs';

export interface RenderOptions {
headers?: Record<string, string | undefined | string[]>;
Expand Down Expand Up @@ -73,6 +74,7 @@ export class Engine {
referrer: options.headers?.referrer as string | undefined,
userAgent: options.headers?.['user-agent'] as string | undefined,
beforeParse: (window) => {
augmentWindowWithStubs(window);
window.ngRenderMode = true;
},
});
Expand Down
19 changes: 19 additions & 0 deletions modules/common/clover/server/src/stubs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import { DOMWindow } from 'jsdom';

function noop(): void {}

export function augmentWindowWithStubs(window: DOMWindow): void {
window.resizeBy = noop;
window.resizeTo = noop;
window.scroll = noop;
window.scrollBy = noop;
window.scrollTo = noop;
}

0 comments on commit 635d61e

Please sign in to comment.