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

Commit 3122a48

Browse files
committed
fix(MutationObserver): executes hooks in the creation zone
1 parent 34dc7ae commit 3122a48

File tree

5 files changed

+32
-20
lines changed

5 files changed

+32
-20
lines changed

Diff for: dist/zone-microtask.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -1500,23 +1500,27 @@ function patchClass(className) {
15001500
if (!OriginalClass) return;
15011501

15021502
global[className] = function (fn) {
1503-
this._o = new OriginalClass(zone.bind(fn, true));
1503+
this._o = new OriginalClass(global.zone.bind(fn, true));
1504+
// Remember where the class was instantiate to execute the enqueueTask and dequeueTask hooks
1505+
this._creationZone = global.zone;
15041506
};
15051507

15061508
var instance = new OriginalClass(function () {});
15071509

15081510
global[className].prototype.disconnect = function () {
15091511
var result = this._o.disconnect.apply(this._o, arguments);
1510-
this._active && global.zone.dequeueTask();
1511-
this._active = false;
1512+
if (this._active) {
1513+
this._creationZone.dequeueTask();
1514+
this._active = false;
1515+
}
15121516
return result;
15131517
};
15141518

15151519
global[className].prototype.observe = function () {
15161520
if (!this._active) {
1517-
global.zone.enqueueTask();
1521+
this._creationZone.enqueueTask();
1522+
this._active = true;
15181523
}
1519-
this._active = true;
15201524
return this._o.observe.apply(this._o, arguments);
15211525
};
15221526

@@ -1534,7 +1538,7 @@ function patchClass(className) {
15341538
Object.defineProperty(global[className].prototype, prop, {
15351539
set: function (fn) {
15361540
if (typeof fn === 'function') {
1537-
this._o[prop] = zone.bind(fn);
1541+
this._o[prop] = global.zone.bind(fn);
15381542
} else {
15391543
this._o[prop] = fn;
15401544
}

0 commit comments

Comments
 (0)