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

Commit

Permalink
fix(duplicate): fix #1081, load patch should also check the duplicate…
Browse files Browse the repository at this point in the history
… flag (#1121)
  • Loading branch information
JiaLiPassion authored and mhevery committed Jan 8, 2019
1 parent 96420d6 commit 8ce5e33
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ const Zone: ZoneType = (function(global: any) {
performance && performance['measure'] && performance['measure'](name, label);
}
mark('Zone');
const checkDuplicate = global[('__zone_symbol__forceDuplicateZoneCheck')] === true;
if (global['Zone']) {
// if global['Zone'] already exists (maybe zone.js was already loaded or
// some other lib also registered a global object named Zone), we may need
Expand All @@ -653,8 +654,7 @@ const Zone: ZoneType = (function(global: any) {
// but when user load page2 again, error occurs because global['Zone'] already exists.
// so we add a flag to let user choose whether to throw this error or not.
// By default, if existing Zone is from zone.js, we will not throw the error.
if (global[('__zone_symbol__forceDuplicateZoneCheck')] === true ||
typeof global['Zone'].__symbol__ !== 'function') {
if (checkDuplicate || typeof global['Zone'].__symbol__ !== 'function') {
throw new Error('Zone already loaded.');
} else {
return global['Zone'];
Expand Down Expand Up @@ -693,7 +693,9 @@ const Zone: ZoneType = (function(global: any) {

static __load_patch(name: string, fn: _PatchFn): void {
if (patches.hasOwnProperty(name)) {
throw Error('Already loaded patch: ' + name);
if (checkDuplicate) {
throw Error('Already loaded patch: ' + name);
}
} else if (!global['__Zone_disable_' + name]) {
const perfName = 'Zone:' + name;
mark(perfName);
Expand Down Expand Up @@ -1364,4 +1366,4 @@ const Zone: ZoneType = (function(global: any) {

performanceMeasure('Zone', 'Zone');
return global['Zone'] = Zone;
})(typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global);
})(typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global);

0 comments on commit 8ce5e33

Please sign in to comment.