Skip to content

Commit 13276ae

Browse files
authored
fix(desktop): apply getComputedStyle polyfill on all platforms (#9369)
1 parent 4299450 commit 13276ae

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

packages/desktop/src/index.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,16 @@ if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
2626
)
2727
}
2828

29-
const isWindows = ostype() === "windows"
30-
if (isWindows) {
31-
const originalGetComputedStyle = window.getComputedStyle
32-
window.getComputedStyle = ((elt: Element, pseudoElt?: string | null) => {
33-
if (!(elt instanceof Element)) {
34-
// WebView2 can call into Floating UI with non-elements; fall back to a safe element.
35-
return originalGetComputedStyle(document.documentElement, pseudoElt ?? undefined)
36-
}
37-
return originalGetComputedStyle(elt, pseudoElt ?? undefined)
38-
}) as typeof window.getComputedStyle
39-
}
29+
// Floating UI can call getComputedStyle with non-elements (e.g., null refs, virtual elements).
30+
// This happens on all platforms (WebView2 on Windows, WKWebView on macOS), not just Windows.
31+
const originalGetComputedStyle = window.getComputedStyle
32+
window.getComputedStyle = ((elt: Element, pseudoElt?: string | null) => {
33+
if (!(elt instanceof Element)) {
34+
// Fall back to a safe element when a non-element is passed.
35+
return originalGetComputedStyle(document.documentElement, pseudoElt ?? undefined)
36+
}
37+
return originalGetComputedStyle(elt, pseudoElt ?? undefined)
38+
}) as typeof window.getComputedStyle
4039

4140
let update: Update | null = null
4241

0 commit comments

Comments
 (0)