From d8761057ea33c7c0869a05c5d47e8069120e5f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20Marohni=C4=87?= Date: Mon, 8 Apr 2024 03:01:05 +0200 Subject: [PATCH] Use SSR env variable for easier logic separation Since it gets replaced during build, dead code also gets removed. --- app/root.tsx | 3 +-- app/services/dark-mode.tsx | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/root.tsx b/app/root.tsx index a4a46f4..edea97c 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -73,14 +73,13 @@ export function Layout({ children }: { children: React.ReactNode }) { const data = useRouteLoaderData('root') const error = useRouteError() const origin = data?.origin ?? window.location.origin - const hasJs = typeof document !== 'undefined' return ( {data?.appName === 'silvenon-staging' && ( diff --git a/app/services/dark-mode.tsx b/app/services/dark-mode.tsx index 2d5a7aa..077e903 100644 --- a/app/services/dark-mode.tsx +++ b/app/services/dark-mode.tsx @@ -24,7 +24,7 @@ function DarkModeProvider({ sessionValue, children }: ProviderProps) { const sessionFetcher = useFetcher({ key: FETCHER_KEY }) const optimisticSessionValueRef = useRef(undefined) const [matchesValue, setMatchesValue] = useState(() => { - if (typeof document === 'undefined') { + if (import.meta.env.SSR) { // there's no way for us to know what the theme should be in this context // the client will have to figure it out before hydration. return null