Skip to content

Commit

Permalink
🐛 bootstrapping patch just run once but freer will called repeatedly (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kuitos committed Jun 11, 2020
1 parent f468237 commit cdeeac9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
9 changes: 4 additions & 5 deletions src/sandbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ import SnapshotSandbox from './snapshotSandbox';
* @param singular
*/
export function createSandbox(appName: string, elementGetter: () => HTMLElement | ShadowRoot, singular: boolean) {
// mounting freers are one-off and should be re-init at every mounting time
let mountingFreers: Freer[] = [];

let sideEffectsRebuilders: Rebuilder[] = [];

let sandbox: SandBox;
if (window.Proxy) {
sandbox = singular ? new LegacySandbox(appName) : new ProxySandbox(appName);
Expand All @@ -39,6 +34,10 @@ export function createSandbox(appName: string, elementGetter: () => HTMLElement

// some side effect could be be invoked while bootstrapping, such as dynamic stylesheet injection with style-loader, especially during the development phase
const bootstrappingFreers = patchAtBootstrapping(appName, elementGetter, sandbox.proxy, singular);
// mounting freers are one-off and should be re-init at every mounting time
let mountingFreers: Freer[] = [];

let sideEffectsRebuilders: Rebuilder[] = [];

return {
proxy: sandbox.proxy,
Expand Down
16 changes: 8 additions & 8 deletions src/sandbox/patchers/dynamicHeadAppend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ function getNewInsertBefore(...args: any[]) {
};
}

let patchCount = 0;
let bootstrappingPatchCount = 0;
let mountingPatchCount = 0;

/**
* Just hijack dynamic head append, that could avoid accidentally hijacking the insertion of elements except in head.
Expand Down Expand Up @@ -351,17 +352,16 @@ export default function patch(
);
}

if (mounting) {
patchCount++;
}
if (!mounting) bootstrappingPatchCount++;
if (mounting) mountingPatchCount++;

return function free() {
if (mounting) {
patchCount--;
}
// bootstrap patch just called once but its freer will be called multiple times
if (!mounting && bootstrappingPatchCount !== 0) bootstrappingPatchCount--;
if (mounting) mountingPatchCount--;

// release the overwrite prototype after all the micro apps unmounted
if (patchCount === 0) {
if (mountingPatchCount === 0 && bootstrappingPatchCount === 0) {
HTMLHeadElement.prototype.appendChild = rawHeadAppendChild;
HTMLHeadElement.prototype.insertBefore = rawHeadInsertBefore;
HTMLHeadElement.prototype.removeChild = rawHeadRemoveChild;
Expand Down

1 comment on commit cdeeac9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for qiankun ready!

Built with commit cdeeac9

https://qiankun-bk388rx95.now.sh

Please sign in to comment.