From a4ee20f9c2e34888b6615883c79aa1e44ef0dd9f Mon Sep 17 00:00:00 2001
From: WhaleSong <1196032724@qq.com>
Date: Sun, 11 Jun 2023 16:24:14 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E9=80=82=E9=85=8D=E8=8E=B7=E5=8F=96shad?=
 =?UTF-8?q?owDom=E4=B8=ADhtml=E7=9A=84clientHeight?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 packages/wujie-core/src/shadow.ts | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/packages/wujie-core/src/shadow.ts b/packages/wujie-core/src/shadow.ts
index 92a1e3685..3c3f1e506 100644
--- a/packages/wujie-core/src/shadow.ts
+++ b/packages/wujie-core/src/shadow.ts
@@ -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
  */
@@ -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);
 }