Skip to content

fix(@angular/build): ensure Sass importers return global Promise instances - #34310

Merged
dgp1130 merged 3 commits into
angular:mainfrom
alan-agius4:fix/sass-zone-promise
Oct 12, 2026
Merged

dgp1130 merged 3 commits into
angular:mainfrom
alan-agius4:fix/sass-zone-promise

Conversation

@alan-agius4

@alan-agius4 alan-agius4 commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

sass-embedded checks whether an importer's canonicalize method returned a promise using result instanceof Promise. When SSR executes in the same process during ng serve for an application using Zone.js, zone.js/node replaces globalThis.Promise with ZoneAwarePromise. Because native V8 async functions always return instances of the intrinsic V8 %Promise% rather than globalThis.Promise, result instanceof Promise evaluates to false and sass-embedded treats the returned Promise as a synchronous URL value ("[object Promise]" / "%5Bobject%20Promise%5D").

Use Promise.resolve(...) instead of a native async method in AsyncModuleUrlRebasingImporter.canonicalize so the returned promise is constructed via the active globalThis.Promise.

Closes #34309

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses compatibility issues with sass-embedded when globalThis.Promise is replaced (e.g., by Zone.js during SSR). It modifies AsyncModuleUrlRebasingImporter.canonicalize and SassCompiler.compileStringAsync to ensure returned promises are instances of the current globalThis.Promise by using Promise.resolve instead of native async methods. A comprehensive test simulating Zone.js behavior is also added. The review feedback highlights three key issues in the sass-service.ts implementation: the potential loss of other importer properties when mapping options.importers, the unnecessary wrapping of synchronous returns in promises, and the lack of wrapping for standard Importers' canonicalize method.

@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Oct 12, 2026
@alan-agius4
alan-agius4 requested a review from clydin October 12, 2026 10:26
…ances

`sass-embedded` checks whether an importer's `canonicalize` or `findFileUrl`
method returned a promise using `result instanceof Promise`. When SSR executes
in the same process during `ng serve` for an application using Zone.js,
`zone.js/node` replaces `globalThis.Promise` with `ZoneAwarePromise`. Because
native V8 `async` functions always return instances of the intrinsic V8
`%Promise%` rather than `globalThis.Promise`, `result instanceof Promise`
evaluates to `false` and `sass-embedded` treats the returned Promise as a
synchronous URL value (`"[object Promise]"` / `"%5Bobject%20Promise%5D"`).

Use `Promise.resolve(...)` instead of a native `async` method in
`AsyncModuleUrlRebasingImporter.canonicalize` and wrap `FileImporter.findFileUrl`
with `Promise.resolve(...)` so the returned promises are constructed via the
active `globalThis.Promise`.

Closes angular#34309
@alan-agius4
alan-agius4 force-pushed the fix/sass-zone-promise branch from 4138fde to 9602f2f Compare October 12, 2026 11:25
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Oct 12, 2026
@dgp1130
dgp1130 merged commit 47c328d into angular:main Oct 12, 2026
40 checks passed
@dgp1130

dgp1130 commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

This PR was merged into the repository. The changes were merged into the following branches:

@angular-automatic-lock-bot

Copy link
Copy Markdown

This pull request has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Nov 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: The importer must return an absolute URL, was "[object Promise]"

3 participants