Skip to content

Commit d876105

Browse files
committed
Use SSR env variable for easier logic separation
Since it gets replaced during build, dead code also gets removed.
1 parent 733df68 commit d876105

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

app/root.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,13 @@ export function Layout({ children }: { children: React.ReactNode }) {
7373
const data = useRouteLoaderData<typeof loader>('root')
7474
const error = useRouteError()
7575
const origin = data?.origin ?? window.location.origin
76-
const hasJs = typeof document !== 'undefined'
7776

7877
return (
7978
<AnalyticsProvider>
8079
<DarkMode.Provider sessionValue={error !== null || data?.darkMode}>
8180
<DarkMode.Html
8281
lang="en"
83-
className={clsx('h-full', hasJs ? 'js' : 'no-js')}
82+
className={clsx('h-full', import.meta.env.SSR ? 'no-js' : 'js')}
8483
>
8584
<head>
8685
{data?.appName === 'silvenon-staging' && (

app/services/dark-mode.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function DarkModeProvider({ sessionValue, children }: ProviderProps) {
2424
const sessionFetcher = useFetcher({ key: FETCHER_KEY })
2525
const optimisticSessionValueRef = useRef<boolean | undefined>(undefined)
2626
const [matchesValue, setMatchesValue] = useState<boolean | null>(() => {
27-
if (typeof document === 'undefined') {
27+
if (import.meta.env.SSR) {
2828
// there's no way for us to know what the theme should be in this context
2929
// the client will have to figure it out before hydration.
3030
return null

0 commit comments

Comments
 (0)