Repository navigation
fix(@angular/build): ensure Sass importers return global Promise instances - #34310
Conversation
There was a problem hiding this comment.
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.
…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
4138fde to
9602f2f
Compare
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
sass-embeddedchecks whether an importer'scanonicalizemethod returned a promise usingresult instanceof Promise. When SSR executes in the same process duringng servefor an application using Zone.js,zone.js/nodereplacesglobalThis.PromisewithZoneAwarePromise. Because native V8asyncfunctions always return instances of the intrinsic V8%Promise%rather thanglobalThis.Promise,result instanceof Promiseevaluates tofalseandsass-embeddedtreats the returned Promise as a synchronous URL value ("[object Promise]"/"%5Bobject%20Promise%5D").Use
Promise.resolve(...)instead of a nativeasyncmethod inAsyncModuleUrlRebasingImporter.canonicalizeso the returned promise is constructed via the activeglobalThis.Promise.Closes #34309