-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add Support for strategy
Prop from Next.js Script Library
#150
base: development
Are you sure you want to change the base?
Conversation
@HofmannZ Would love for you to take a look at this |
This reverts commit 24c3844.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Unsleeping - I'm happy to add some flexibility to the package, just curious how safe afterInteractive
is to use. We chose beforeInteractive
because it runs before any Next.js code and before any page hydration occurs, allowing us to use the env vars everywhere.
afterInteractive
loads early but after some hydration on the page occurs.
CC: @davevanhoorn
Following up on my prior message, the real problem is this bug in Next.js: vercel/next.js#69567 (comment) |
The issue was discussed in a thread, and here’s a brief summary: When rendering the not-found page, Next.js throws a specific error and reacts to all errors in the same way — it stops rendering the page, including the root layout where next-runtime-env configuration assignment occurs. As explained in the thread, the problem is that Next.js halts the rendering of any page when an error occurs, whether it’s a Basically, the rendering of a page is stopped whenever any error is encountered. Regardless of whether the error is caused by However, all other loading strategies, such as I’m actively testing the That’s why I kept We need to look into this more deeply and possibly switch from |
The only issue I've encountered so far after switching to For example, something like this:
In this case, In the Next.js documentation for the
This explains why the previous behavior wasn't breaking, but after switching to p.s. same with |
This pull request enhances the
next-runtime-env
library by adding support for thestrategy
prop from the Next.jsnext/script
component. The change addresses issues #145 and #147, and helps improve runtime environment configuration retrieval on the not-found page.Key Changes:
strategy
prop to allow customization of script loading behavior (e.g.,beforeInteractive
,afterInteractive
).beforeInteractive
, following current practices. This ensures backward compatibility, but the default strategy can now be adjusted as needed.Observations:
During testing, I noticed that with the
beforeInteractive
strategy, I was unable to retrieve the runtime environment configuration on thenot-found
page.When using afterInteractive, the environment config is successfully retrieved and assigned to
window
on thenot-found
page.So, I need to know about the exact limitations of the
beforeInteractive
strategy, as it seems hardcoded to load scripts early. I might have misunderstood something, and further clarification would be helpful.For reference, here's the relevant Next.js documentation on the beforeInteractive strategy: Next.js Script beforeInteractive Documentation.