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.
  • Loading branch information
alan-agius4 committed Oct 27, 2022
1 parent 8e78224 commit b7dbc25
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions modules/builders/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ts_library(
deps = [
"//modules/common/clover/server",
"//modules/common/engine",
"//modules/common/tools",
"@npm//@angular-devkit/architect",
"@npm//@angular-devkit/build-angular",
"@npm//@angular-devkit/core",
Expand Down
12 changes: 8 additions & 4 deletions modules/builders/src/prerender/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import type { Type } from '@angular/core';
import type * as platformServer from '@angular/platform-server';
import type { ɵInlineCriticalCssProcessor } from '@nguniversal/common/tools';
import assert from 'node:assert';
import * as fs from 'node:fs';
import * as path from 'node:path';
Expand Down Expand Up @@ -89,10 +90,6 @@ async function render({
});

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

const inlineCriticalCssProcessor = new InlineCriticalCssProcessor({
deployUrl: deployUrl,
minify: minifyCss,
Expand All @@ -118,13 +115,20 @@ async function render({
return result;
}

let InlineCriticalCssProcessor: typeof ɵInlineCriticalCssProcessor;
/**
* Initializes the worker when it is first created by loading the Zone.js package
* into the worker instance.
*
* @returns A promise resolving to the render function of the worker.
*/
async function initialize() {
const { ɵInlineCriticalCssProcessor } = await loadEsmModule<
typeof import('@nguniversal/common/tools')
>('@nguniversal/common/tools');

InlineCriticalCssProcessor = ɵInlineCriticalCssProcessor;

// Setup Zone.js
await import(zonePackage);

Expand Down

0 comments on commit b7dbc25

Please sign in to comment.