File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ export default function RootLayout({
8989 className = { `${ geistSans . variable } ${ geistMono . variable } bg-gray-50 text-gray-900 antialiased transition-colors duration-300 dark:bg-neutral-950 dark:text-gray-100` }
9090 >
9191 { children }
92- { process . env . NODE_ENV === 'production ' && < Analytics /> }
92+ { process . env . VERCEL === '1 ' && < Analytics /> }
9393 </ body >
9494 </ html >
9595 ) ;
Original file line number Diff line number Diff line change @@ -4,14 +4,30 @@ type NetlifyEnv = {
44 get ?: ( key : string ) => string | undefined ;
55} ;
66
7+ type NetlifyRuntime = {
8+ env ?: NetlifyEnv ;
9+ } ;
10+
11+ declare const Netlify : NetlifyRuntime | undefined ;
12+
13+ function getNetlifyRuntime ( ) : NetlifyRuntime | undefined {
14+ const fromGlobalThis = ( globalThis as { Netlify ?: NetlifyRuntime } ) . Netlify ;
15+ if ( fromGlobalThis ) return fromGlobalThis ;
16+
17+ if ( typeof Netlify !== 'undefined' ) return Netlify ;
18+
19+ return undefined ;
20+ }
21+
722function readFromNetlifyEnv ( key : string ) : string | undefined {
8- const maybeNetlify = ( globalThis as { Netlify ?: { env ?: NetlifyEnv } } ) . Netlify ;
9- const value = maybeNetlify ?. env ?. get ?.( key ) ;
23+ const runtime = getNetlifyRuntime ( ) ;
24+ const value = runtime ?. env ?. get ?.( key ) ;
1025 return typeof value === 'string' && value . trim ( ) ? value . trim ( ) : undefined ;
1126}
1227
1328export function readServerEnv ( key : string ) : string | undefined {
1429 const fromProcess = process . env [ key ] ?. trim ( ) ;
1530 if ( fromProcess ) return fromProcess ;
31+
1632 return readFromNetlifyEnv ( key ) ;
1733}
You can’t perform that action at this time.
0 commit comments