diff --git a/CHANGELOG.md b/CHANGELOG.md index 60031facf..86893aa6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,13 @@ ### Node JS API -* Fixes Electron support when `nodeIntegration` is disabled +* Fix a few infrequent errors when calling `render()` with `fiber` multiple + times simultaneously. + +* Avoid possible mangled error messages when custom functions or importers throw + unexpected exceptions. + +* Fix Electron support when `nodeIntegration` is disabled. ## 1.32.4 diff --git a/lib/src/node.dart b/lib/src/node.dart index b5c500dfc..1711875a5 100644 --- a/lib/src/node.dart +++ b/lib/src/node.dart @@ -65,13 +65,13 @@ void main() { /// /// [render]: https://github.com/sass/node-sass#options void _render( - RenderOptions options, void callback(JsError error, RenderResult result)) { + RenderOptions options, void callback(Object error, RenderResult result)) { if (options.fiber != null) { options.fiber.call(allowInterop(() { try { callback(null, _renderSync(options)); } catch (error) { - callback(error as JsError, null); + callback(error, null); } return null; })).run(); @@ -212,8 +212,12 @@ List _parseFunctions(RenderOptions options, }) ]; var result = Function.apply(callback as Function, jsArguments); - return unwrapValue( - isUndefined(result) ? options.fiber.yield() : result); + return unwrapValue(isUndefined(result) + // Run `fiber.yield()` in runZoned() so that Dart resets the current + // zone once it's done. Otherwise, interweaving fibers can leave + // `Zone.current` in an inconsistent state. + ? runZoned(() => options.fiber.yield()) + : result); })); } else if (!asynch) { result.add(BuiltInCallable.parsed( @@ -283,7 +287,11 @@ NodeImporter _parseImporter(RenderOptions options, DateTime start) { // [importer] calls `done()` synchronously. scheduleMicrotask(() => fiber.run(result)); })); - if (isUndefined(result)) return options.fiber.yield(); + + // Run `fiber.yield()` in runZoned() so that Dart resets the current + // zone once it's done. Otherwise, interweaving fibers can leave + // `Zone.current` in an inconsistent state. + if (isUndefined(result)) return runZoned(() => options.fiber.yield()); return result; }) as JSFunction; }).toList(); diff --git a/pubspec.yaml b/pubspec.yaml index 92ed76272..73782ea6c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: sass -version: 1.32.5-dev +version: 1.32.5 description: A Sass implementation in Dart. author: Sass Team homepage: https://github.com/sass/dart-sass