app/root.tsx - Referenceing ENV rather than env prop in Document? #909
-
I noticed this line in Shouldn't this be function Document({
children,
nonce,
theme = 'light',
env = {},
}: {
children: React.ReactNode
nonce: string
theme?: Theme
env?: Record<string, string | undefined>
allowIndexing?: boolean
}) {
const allowIndexing = ENV.ALLOW_INDEXING !== 'false'
return (
<html lang="en" className={`${theme} h-full overflow-x-hidden`}>
<head>
<ClientHintCheck nonce={nonce} />
<Meta />
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
{allowIndexing ? null : (
<meta name="robots" content="noindex, nofollow" />
)}
<Links />
</head>
<body className="bg-background text-foreground">
{children}
<script
nonce={nonce}
dangerouslySetInnerHTML={{
__html: `window.ENV = ${JSON.stringify(env)}`,
}}
/>
<ScrollRestoration nonce={nonce} />
<Scripts nonce={nonce} />
</body>
</html>
)
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
That will work either way. I should probably document the environment variable setup (it's set up in this part of Epic Web: https://foundations.epicweb.dev/exercise/05/03/problem). |
Beta Was this translation helpful? Give feedback.
That will work either way. I should probably document the environment variable setup (it's set up in this part of Epic Web: https://foundations.epicweb.dev/exercise/05/03/problem).
ENV
is a global variable in both server and browser that resolves to the same thing asenv
in this context.