Skip to content

Commit

Permalink
🎨 optimize code and support for scenario of dynamic script comment as…
Browse files Browse the repository at this point in the history
… reference node (#2576)
  • Loading branch information
kuitos authored Aug 7, 2023
1 parent 425110e commit 3878cea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/sandbox/patchers/dynamicAppend/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ type DynamicDomMutationTarget = 'head' | 'body';
declare global {
interface HTMLLinkElement {
[styleElementTargetSymbol]: DynamicDomMutationTarget;
[styleElementRefNodeNo]?: number;
[styleElementRefNodeNo]?: Exclude<number, -1>;
}

interface HTMLStyleElement {
[styleElementTargetSymbol]: DynamicDomMutationTarget;
[styleElementRefNodeNo]?: number;
[styleElementRefNodeNo]?: Exclude<number, -1>;
}

interface Function {
Expand Down
9 changes: 4 additions & 5 deletions src/sandbox/patchers/dynamicAppend/forStrictSandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,10 @@ export function patchStrictSandbox(
const refNo = stylesheetElement[styleElementRefNodeNo];

if (typeof refNo === 'number' && refNo !== -1) {
const refNode = mountDom.childNodes[refNo];
if (refNode) {
rawHeadInsertBefore.call(mountDom, stylesheetElement, refNode);
return true;
}
// the reference node may be dynamic script comment which is not rebuilt while remounting thus reference node no longer exists
const refNode = mountDom.childNodes[refNo] || null;
rawHeadInsertBefore.call(mountDom, stylesheetElement, refNode);
return true;
} else {
rawHeadAppendChild.call(mountDom, stylesheetElement);
return true;
Expand Down

1 comment on commit 3878cea

@vercel
Copy link

@vercel vercel bot commented on 3878cea Aug 7, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

qiankun – ./

qiankun-git-master-chencheng.vercel.app
qiankun-chencheng.vercel.app
qiankun.vercel.app
qiankun.umijs.org

Please sign in to comment.