Skip to content

Commit

Permalink
fix(@nguniversal/builders): address method Promise.prototype.then cal…
Browse files Browse the repository at this point in the history
…led on incompatible receiver error

Prerendering does not work when using Node.js versions that contain the following commit nodejs/node#43728 due to `loadesm` is now using `SafePromiseAll` which is not handled properly by zone.js.

With this chage we introduce a workaround until it's fix upstream.
  • Loading branch information
alan-agius4 committed Oct 26, 2022
1 parent 92d2f8e commit 8e8fc81
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions modules/builders/src/prerender/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,21 @@ async function render({
});

if (inlineCriticalCss) {
// The below zone.js patches are a workaround for https://github.com/angular/angular/issues/47872
// which is caused by https://github.com/nodejs/node/pull/43728.
// Note: this workaround has been suggested by Jia Li as intermin solution until a proper fix is found.
const ZoneAwarePromise = global.Promise;
global.Promise = (global as any)[Zone.__symbol__('Promise')];
const ZoneAwarePromiseThen = global.Promise.prototype.then;
global.Promise.prototype.then = (global as any).Promise.prototype[Zone.__symbol__('then')];

const { ɵInlineCriticalCssProcessor: InlineCriticalCssProcessor } = await loadEsmModule<
typeof import('@nguniversal/common/tools')
>('@nguniversal/common/tools');

global.Promise = ZoneAwarePromise;
global.Promise.prototype.then = ZoneAwarePromiseThen;

const inlineCriticalCssProcessor = new InlineCriticalCssProcessor({
deployUrl: deployUrl,
minify: minifyCss,
Expand Down

0 comments on commit 8e8fc81

Please sign in to comment.