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

🎨 optimize code and support for scenario of dynamic script comment as reference node #2576

Merged
merged 1 commit into from
Aug 7, 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
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
Loading