Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nextjs 14.2.5 (and older): notfound() / not-found client components don't have access to the environment variables. #147

Open
agustingabiola opened this issue Aug 13, 2024 · 2 comments

Comments

@agustingabiola
Copy link

agustingabiola commented Aug 13, 2024

Issue

When a page defaults to the not-found page client components fail to load the environment variables (all NEXT_PUBLIC) are undefined while on the server they have the correct values.

This is happening in all 3.X versions I tried and with Nextjs app router v14

@Unsleeping
Copy link

Unsleeping commented Sep 13, 2024

Even if the not-found component is server-side, after the redirect to the page, the entire window.__ENV becomes undefined, and env("ENV_KEY") also becomes undefined.

fixes with changing router.push() to window.location.href
without page refresh it works as expected

only happens from navigation from not-found page

@Unsleeping
Copy link

@agustingabiola Hi! Since my PR #150 hasn't received a response, I've published my fork on npm.

You can switch to awesome-next-runtime-env and be sure to configure the strategy prop for the assignment in your Root Layout:

<head>
   <PublicEnvScript strategy="afterInteractive" />
 </head>

For more information about the issue, check out: vercel/next.js#69567 (comment)
Forked version: #150

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants