Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 531d0ec

Browse files
IgorMinarvicb
authored andcommitted
fix: don't fork new zones for callbacks from the root zone
BREAKING CHANGE: New child zones are now created only from a async task that installed a custom zone. Previously even without a custom zone installed (e.g. LongStacktracesZone), we would spawn new child zones for all asynchronous events. This is undesirable and generally not useful. It does not make sense for us to create new zones for callbacks from the root zone since we care only about callbacks from installed custom zones. This reduces the overhead of zones. This primarily means that LongStackTraces zone won't be able to trace events back to Zone.init(), but instead the starting point will be the installation of the LongStacktracesZone. In all practical situations this should be sufficient. Closes #92
1 parent bf925bf commit 531d0ec

File tree

6 files changed

+29
-5
lines changed

6 files changed

+29
-5
lines changed

Diff for: dist/zone-microtask.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Zone.prototype = {
8383

8484
bind: function (fn, skipEnqueue) {
8585
skipEnqueue || this.enqueueTask(fn);
86-
var zone = this.fork();
86+
var zone = this.isRootZone() ? this : this.fork();
8787
return function zoneBoundFn() {
8888
return zone.run(fn, this, arguments);
8989
};

Diff for: dist/zone-microtask.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/zone.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Zone.prototype = {
7878

7979
bind: function (fn, skipEnqueue) {
8080
skipEnqueue || this.enqueueTask(fn);
81-
var zone = this.fork();
81+
var zone = this.isRootZone() ? this : this.fork();
8282
return function zoneBoundFn() {
8383
return zone.run(fn, this, arguments);
8484
};

Diff for: dist/zone.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: lib/core.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Zone.prototype = {
5959

6060
bind: function (fn, skipEnqueue) {
6161
skipEnqueue || this.enqueueTask(fn);
62-
var zone = this.fork();
62+
var zone = this.isRootZone() ? this : this.fork();
6363
return function zoneBoundFn() {
6464
return zone.run(fn, this, arguments);
6565
};

Diff for: test/zone.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,30 @@ describe('Zone', function () {
149149
});
150150

151151

152+
describe('bind', function() {
153+
154+
it('should execute all callbacks from root zone without forking zones', function(done) {
155+
// using setTimeout for the test which relies on patching via bind
156+
setTimeout(function() {
157+
expect(zone.isRootZone()).toBe(true);
158+
done();
159+
});
160+
});
161+
162+
163+
it('should fork a zone for non-root zone', function(done) {
164+
// using setTimeout for the test which relies on patching via bind
165+
var childZone = zone.fork();
166+
childZone.run(function() {
167+
setTimeout(function() {
168+
expect(zone.parent).toBe(childZone);
169+
done();
170+
});
171+
});
172+
});
173+
});
174+
175+
152176
describe('fork', function () {
153177
it('should fork deep copy', function () {
154178
var protoZone = { too: { deep: true } },

0 commit comments

Comments
 (0)