Skip to content

Commit

Permalink
Merge pull request #1208 from sass/node-api-bugs
Browse files Browse the repository at this point in the history
Fix a few Node.js API bugs
  • Loading branch information
nex3 committed Jan 20, 2021
2 parents f0720f2 + 474956d commit d5207f8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 13 additions & 5 deletions lib/src/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -212,8 +212,12 @@ List<AsyncCallable> _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(
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit d5207f8

Please sign in to comment.