Skip to content
Open
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
23 changes: 15 additions & 8 deletions packages/wujie-core/src/shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ function renderTemplateToHtml(iframeWindow: Window, template: string): HTMLHtmlE
return html;
}

function adaptedShadowRootHtml(shadowRoot: ShadowRoot, iframeWindow: Window) {
Object.defineProperty(shadowRoot.firstChild, "parentNode", {
enumerable: true,
configurable: true,
get: () => iframeWindow.document,
});
// https://www.w3.org/TR/2016/WD-cssom-view-1-20160317/#dom-element-clientheight
Object.defineProperty(shadowRoot.firstChild, "clientHeight", {
enumerable: true,
configurable: true,
get: () => iframeWindow.parent?.document.documentElement.clientHeight,
});
}

/**
* 将template渲染到shadowRoot
*/
Expand All @@ -224,14 +238,7 @@ export async function renderTemplateToShadowRoot(
processedHtml.insertBefore(shade, processedHtml.firstChild);
shadowRoot.head = shadowRoot.querySelector("head");
shadowRoot.body = shadowRoot.querySelector("body");

// 修复 html parentNode
Object.defineProperty(shadowRoot.firstChild, "parentNode", {
enumerable: true,
configurable: true,
get: () => iframeWindow.document,
});

adaptedShadowRootHtml(shadowRoot, iframeWindow);
patchRenderEffect(shadowRoot, iframeWindow.__WUJIE.id, false);
}

Expand Down