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

Commit a86c6d5

Browse files
JiaLiPassionmhevery
authored andcommitted
feat(Core): fix #910, add a flag to allow user to ignore duplicate Zone error (#1093)
1 parent bf88c34 commit a86c6d5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/zone.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,21 @@ const Zone: ZoneType = (function(global: any) {
644644
}
645645
mark('Zone');
646646
if (global['Zone']) {
647-
throw new Error('Zone already loaded.');
647+
// if global['Zone'] already exists (maybe zone.js was already loaded or
648+
// some other lib also registered a global object named Zone), we may need
649+
// to throw an error, but sometimes user may not want this error.
650+
// For example,
651+
// we have two web pages, page1 includes zone.js, page2 doesn't.
652+
// and the 1st time user load page1 and page2, everything work fine,
653+
// but when user load page2 again, error occurs because global['Zone'] already exists.
654+
// so we add a flag to let user choose whether to throw this error or not.
655+
// By default, if existing Zone is from zone.js, we will not throw the error.
656+
if (global[('__zone_symbol__forceDuplicateZoneCheck')] === true ||
657+
typeof global['Zone'].__symbol__ !== 'function') {
658+
throw new Error('Zone already loaded.');
659+
} else {
660+
return global['Zone'];
661+
}
648662
}
649663

650664
class Zone implements AmbientZone {

0 commit comments

Comments
 (0)