Run extension handlers in the registering zone

Towards https://github.com/flutter/flutter/issues/93676

Flutter uses an extension for hot reloads, and the app ends up running
in the root zone after a hot reload because that is the zone that the
handler gets called in.

Always run extension handler callbacks in the zone from which they were
registered for more predictable behavior.

Change-Id: Ia921489a6ada802c8e53a0ccc650a8bce218ba01
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/275842
Commit-Queue: Ben Konyi <bkonyi@google.com>
Auto-Submit: Nate Bosch <nbosch@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
This commit is contained in:
Nate Bosch 2022-12-15 15:05:17 +00:00 committed by Commit Queue
parent d02e1de5b1
commit ca03588d2b
2 changed files with 4 additions and 1 deletions

View file

@ -62,6 +62,8 @@
- **Breaking change** [#49529][]:
- Removed the deprecated [`MAX_USER_TAGS`][] constant.
Use [`maxUserTags`][] instead.
- Callbacks passed to `registerExtension` will be run in the zone from which
they are registered.
[#49529]: https://github.com/dart-lang/sdk/issues/49529
[`MAX_USER_TAGS`]: https://api.dart.dev/stable/dart-developer/UserTag/MAX_USER_TAGS-constant.html

View file

@ -122,7 +122,8 @@ void registerExtension(String method, ServiceExtensionHandler handler) {
}
// TODO: When NNBD is complete, delete the following line.
checkNotNullable(handler, 'handler');
_registerExtension(method, handler);
final zoneHandler = Zone.current.bindBinaryCallback(handler);
_registerExtension(method, zoneHandler);
}
/// Whether the "Extension" stream currently has at least one listener.