From ca44986e008ff85dd4795c4d25ee9d65b9139898 Mon Sep 17 00:00:00 2001 From: Nicky Date: Thu, 2 Apr 2020 12:28:34 +0200 Subject: [PATCH 1/2] feat: added mocks for browser to fix window, document, HTMLElement and navigator issues on server --- server.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server.ts b/server.ts index a86b7098da..1550cfcf22 100644 --- a/server.ts +++ b/server.ts @@ -1,3 +1,4 @@ +// tslint:disable:no-string-literal // tslint:disable: no-console ish-ordered-imports /** * *** NOTE ON IMPORTING FROM ANGULAR AND NGUNIVERSAL IN THIS FILE *** @@ -58,6 +59,16 @@ if (process.env.TRUST_ICM) { console.warn("ignoring all TLS verification as 'TRUST_ICM' variable is set - never use this in production!"); } +// prevent ssr issues regarding window, document, HTMLElement and navigator +const domino = require('domino'); +const template = fs.readFileSync(join(DIST_FOLDER, 'browser', 'index.html')).toString(); +const win = domino.createWindow(template); + +global['window'] = win; +global['document'] = win.document; +global['HTMLElement'] = win.HTMLElement; +global['navigator'] = win.navigator; + // Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine) app.engine( 'html', From ed5de4667a6fe26f9ae45b042796ee38d9268775 Mon Sep 17 00:00:00 2001 From: Danilo Hoffmann Date: Fri, 3 Apr 2020 11:41:24 +0200 Subject: [PATCH 2/2] fixup! feat: added mocks for browser to fix window, document, HTMLElement and navigator issues on server --- server.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server.ts b/server.ts index 1550cfcf22..aacedd091e 100644 --- a/server.ts +++ b/server.ts @@ -1,4 +1,3 @@ -// tslint:disable:no-string-literal // tslint:disable: no-console ish-ordered-imports /** * *** NOTE ON IMPORTING FROM ANGULAR AND NGUNIVERSAL IN THIS FILE *** @@ -59,15 +58,20 @@ if (process.env.TRUST_ICM) { console.warn("ignoring all TLS verification as 'TRUST_ICM' variable is set - never use this in production!"); } -// prevent ssr issues regarding window, document, HTMLElement and navigator +// uncomment this block to prevent ssr issues with third-party libraries regarding window, document, HTMLElement and navigator +// tslint:disable-next-line: no-commented-out-code +/* const domino = require('domino'); const template = fs.readFileSync(join(DIST_FOLDER, 'browser', 'index.html')).toString(); const win = domino.createWindow(template); +// tslint:disable:no-string-literal global['window'] = win; global['document'] = win.document; global['HTMLElement'] = win.HTMLElement; global['navigator'] = win.navigator; +// tslint:enable:no-string-literal +*/ // Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine) app.engine(