Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛parallel sandbox should use different compartment id #2723

Merged
merged 3 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/metal-cougars-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@qiankunjs/sandbox": patch
---

🐛parallel sandbox should use different compartment id
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions packages/sandbox/src/core/compartment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,21 @@ 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;

private constantIntrinsicNames: string[] = [];

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 {
Expand All @@ -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})();`;
}
Expand Down