Просмотр исходного кода

fix(desktop): apply getComputedStyle polyfill on all platforms (#9369)

Slone 2 месяцев назад
Родитель
Сommit
13276aee82
1 измененных файлов с 10 добавлено и 11 удалено
  1. 10 11
      packages/desktop/src/index.tsx

+ 10 - 11
packages/desktop/src/index.tsx

@@ -26,17 +26,16 @@ if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
   )
 }
 
-const isWindows = ostype() === "windows"
-if (isWindows) {
-  const originalGetComputedStyle = window.getComputedStyle
-  window.getComputedStyle = ((elt: Element, pseudoElt?: string | null) => {
-    if (!(elt instanceof Element)) {
-      // WebView2 can call into Floating UI with non-elements; fall back to a safe element.
-      return originalGetComputedStyle(document.documentElement, pseudoElt ?? undefined)
-    }
-    return originalGetComputedStyle(elt, pseudoElt ?? undefined)
-  }) as typeof window.getComputedStyle
-}
+// Floating UI can call getComputedStyle with non-elements (e.g., null refs, virtual elements).
+// This happens on all platforms (WebView2 on Windows, WKWebView on macOS), not just Windows.
+const originalGetComputedStyle = window.getComputedStyle
+window.getComputedStyle = ((elt: Element, pseudoElt?: string | null) => {
+  if (!(elt instanceof Element)) {
+    // Fall back to a safe element when a non-element is passed.
+    return originalGetComputedStyle(document.documentElement, pseudoElt ?? undefined)
+  }
+  return originalGetComputedStyle(elt, pseudoElt ?? undefined)
+}) as typeof window.getComputedStyle
 
 let update: Update | null = null