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

fix(duplicate): fix #1081, load patch should also check the duplicate flag #1121

Merged
merged 1 commit into from
Jan 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);