diff --git a/.changeset/metal-cougars-help.md b/.changeset/metal-cougars-help.md new file mode 100644 index 000000000..6dc041ac7 --- /dev/null +++ b/.changeset/metal-cougars-help.md @@ -0,0 +1,5 @@ +--- +"@qiankunjs/sandbox": patch +--- + +🐛parallel sandbox should use different compartment id diff --git a/.gitignore b/.gitignore index 39cdfa1b3..53b288827 100755 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,8 @@ package-lock.json .now .pnpm-store *.log +packages/qiankun/src/version.ts +packages/sandbox/src/core/sandbox/globals.ts .dumi/tmp .dumi/tmp-test .dumi/tmp-production diff --git a/packages/sandbox/src/core/compartment/index.ts b/packages/sandbox/src/core/compartment/index.ts index f06e74263..a08c57b18 100644 --- a/packages/sandbox/src/core/compartment/index.ts +++ b/packages/sandbox/src/core/compartment/index.ts @@ -27,13 +27,7 @@ export class Compartment { /** * Since the time of execution of the code in Compartment is determined by the browser, a unique compartmentSpecifier should be generated in Compartment */ - private readonly id: CompartmentGlobalId = (() => { - // make sure the compartmentSpecifier is unique - while (nativeGlobal[getCompartmentGlobalId(compartmentCounter)]) { - compartmentCounter++; - } - return getCompartmentGlobalId(compartmentCounter); - })(); + private readonly id: CompartmentGlobalId; private readonly _globalThis: WindowProxy; @@ -41,6 +35,13 @@ export class Compartment { constructor(globalProxy: WindowProxy) { this._globalThis = globalProxy; + + // make sure the compartmentSpecifier is unique + while (nativeGlobal[getCompartmentGlobalId(compartmentCounter)]) { + compartmentCounter++; + } + this.id = getCompartmentGlobalId(compartmentCounter); + nativeGlobal[this.id] = globalProxy; } get globalThis(): WindowProxy { @@ -58,7 +59,6 @@ export class Compartment { ? `const {${this.constantIntrinsicNames.join(',')}} = this;` : ''; - nativeGlobal[this.id] = this.globalThis; // eslint-disable-next-line max-len return `;(function(){with(this){${globalObjectOptimizer}${source}\n${sourceMapURL}}}).bind(window.${this.id})();`; }