fix: wujie shadow root (#1763)

* Fix wujie monkeypatches ownerDocument

---------

Co-authored-by: wfk007 <wfk007@users.noreply.github.com>
This commit is contained in:
fukang wang
2026-04-01 12:00:00 +08:00
committed by GitHub
parent d70bcf45d7
commit 6a6d036ee3
3 changed files with 20 additions and 3 deletions

View File

@@ -532,14 +532,14 @@ export function getRootShadowHost(n: Node): Node {
}
export function shadowHostInDom(n: Node): boolean {
const doc = n.ownerDocument;
const doc = dom.ownerDocument(n);
if (!doc) return false;
const shadowHost = getRootShadowHost(n);
return dom.contains(doc, shadowHost);
}
export function inDom(n: Node): boolean {
const doc = n.ownerDocument;
const doc = dom.ownerDocument(n);
if (!doc) return false;
return dom.contains(doc, n) || shadowHostInDom(n);
}

View File

@@ -13,7 +13,13 @@ type BasePrototypeCache = {
};
const testableAccessors = {
Node: ['childNodes', 'parentNode', 'parentElement', 'textContent'] as const,
Node: [
'childNodes',
'parentNode',
'parentElement',
'textContent',
'ownerDocument',
] as const,
ShadowRoot: ['host', 'styleSheets'] as const,
Element: ['shadowRoot', 'querySelector', 'querySelectorAll'] as const,
MutationObserver: [] as const,
@@ -169,6 +175,10 @@ export function getUntaintedMethod<
return untaintedMethod.bind(instance) as BasePrototypeCache[K][T];
}
export function ownerDocument(n: Node): Document | null {
return getUntaintedAccessor('Node', n, 'ownerDocument');
}
export function childNodes(n: Node): NodeListOf<Node> {
return getUntaintedAccessor('Node', n, 'childNodes');
}
@@ -266,6 +276,7 @@ export function patch(
}
export default {
ownerDocument,
childNodes,
parentNode,
parentElement,