From bc1e8fea3c0f08d8c09281cf38d52d3e68d07550 Mon Sep 17 00:00:00 2001 From: Simon <10131203+gaomeng1900@users.noreply.github.com> Date: Wed, 17 Dec 2025 14:40:11 +0800 Subject: [PATCH] fix: handle null body element --- packages/ui/src/checkDarkMode.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/ui/src/checkDarkMode.ts b/packages/ui/src/checkDarkMode.ts index 7b2ae12..e4cf890 100644 --- a/packages/ui/src/checkDarkMode.ts +++ b/packages/ui/src/checkDarkMode.ts @@ -6,11 +6,11 @@ function hasDarkModeClass() { const DEFAULT_DARK_MODE_CLASSES = ['dark', 'dark-mode', 'theme-dark', 'night', 'night-mode'] const htmlElement = document.documentElement - const bodyElement = document.body + const bodyElement = document.body || document.documentElement // can be null in some cases // Check class names on and for (const className of DEFAULT_DARK_MODE_CLASSES) { - if (htmlElement.classList.contains(className) || bodyElement.classList.contains(className)) { + if (htmlElement.classList.contains(className) || bodyElement?.classList.contains(className)) { return true } } @@ -70,7 +70,7 @@ function isColorDark(colorString: string, threshold = 128) { function isBackgroundDark() { // We check both and because some pages set the color on const htmlStyle = window.getComputedStyle(document.documentElement) - const bodyStyle = window.getComputedStyle(document.body) + const bodyStyle = window.getComputedStyle(document.body || document.documentElement) // Get background colors const htmlBgColor = htmlStyle.backgroundColor