🎨 optimize code and support for scenario of dynamic script comment as reference node (#2576)
This commit is contained in:
parent
425110e9c0
commit
3878cea04a
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user