🎨 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 {
|
declare global {
|
||||||
interface HTMLLinkElement {
|
interface HTMLLinkElement {
|
||||||
[styleElementTargetSymbol]: DynamicDomMutationTarget;
|
[styleElementTargetSymbol]: DynamicDomMutationTarget;
|
||||||
[styleElementRefNodeNo]?: number;
|
[styleElementRefNodeNo]?: Exclude<number, -1>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface HTMLStyleElement {
|
interface HTMLStyleElement {
|
||||||
[styleElementTargetSymbol]: DynamicDomMutationTarget;
|
[styleElementTargetSymbol]: DynamicDomMutationTarget;
|
||||||
[styleElementRefNodeNo]?: number;
|
[styleElementRefNodeNo]?: Exclude<number, -1>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Function {
|
interface Function {
|
||||||
|
|
|
||||||
|
|
@ -284,11 +284,10 @@ export function patchStrictSandbox(
|
||||||
const refNo = stylesheetElement[styleElementRefNodeNo];
|
const refNo = stylesheetElement[styleElementRefNodeNo];
|
||||||
|
|
||||||
if (typeof refNo === 'number' && refNo !== -1) {
|
if (typeof refNo === 'number' && refNo !== -1) {
|
||||||
const refNode = mountDom.childNodes[refNo];
|
// the reference node may be dynamic script comment which is not rebuilt while remounting thus reference node no longer exists
|
||||||
if (refNode) {
|
const refNode = mountDom.childNodes[refNo] || null;
|
||||||
rawHeadInsertBefore.call(mountDom, stylesheetElement, refNode);
|
rawHeadInsertBefore.call(mountDom, stylesheetElement, refNode);
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
rawHeadAppendChild.call(mountDom, stylesheetElement);
|
rawHeadAppendChild.call(mountDom, stylesheetElement);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user