Skip to content

Commit

Permalink
Dont override global if already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
jackocnr committed Apr 20, 2024
1 parent e53e846 commit 585e0d7
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build/js/intlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -2868,7 +2868,7 @@ var factoryOutput = (() => {
}
return null;
};
if (typeof window === "object") {
if (typeof window === "object" && !window.intlTelInputGlobals) {
const intlTelInputGlobals = {
defaults,
//* Using a global like this allows us to mock it in the tests.
Expand Down
2 changes: 1 addition & 1 deletion build/js/intlTelInput.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion react/build/IntlTelInput.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion react/build/IntlTelInput.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion react/demo/simple-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -26343,7 +26343,7 @@
}
return null;
};
if (typeof window === "object") {
if (typeof window === "object" && !window.intlTelInputGlobals) {
const intlTelInputGlobals = {
defaults,
//* Using a global like this allows us to mock it in the tests.
Expand Down
2 changes: 1 addition & 1 deletion react/demo/validation-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -26343,7 +26343,7 @@
}
return null;
};
if (typeof window === "object") {
if (typeof window === "object" && !window.intlTelInputGlobals) {
const intlTelInputGlobals = {
defaults,
//* Using a global like this allows us to mock it in the tests.
Expand Down
3 changes: 2 additions & 1 deletion src/js/intl-tel-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2365,7 +2365,8 @@ const loadUtils = (path: string): Promise<unknown> | null => {
return null;
};

if (typeof window === "object") {
//* Temp workaround to support the plugin being loaded onto the same page twice (e.g. you use it, and one of your bundled dependencies happens to use it as well) - basically, just don't override window.intlTelInputGlobals if it already exists. Then everything should work fine as long as both plugin scripts are using the same version (meaning the utils and globals APIs are compatible).
if (typeof window === "object" && !window.intlTelInputGlobals) {
const intlTelInputGlobals: ItiGlobals = {
defaults,
//* Using a global like this allows us to mock it in the tests.
Expand Down

0 comments on commit 585e0d7

Please sign in to comment.