NextJS plugin - is it possible to wait for a <Script strategy="beforeInteractive">
to finish before Sentry initialisation?
#9858
Unanswered
DavidBanksNZ
asked this question in
Q&A
Replies: 1 comment
-
If you can guarantee that the script is still loaded early enough so that the SDK can catch all errors this solution should be fine. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So we are using Next for a SSG site. Our environment configuration is loaded as a separate file at run time, so that we use the same build artifacts for each environment apart from which config file is used.
The trouble I'm having is getting Sentry initialisation to wait for that config script to load.
Each config script sets up a global config object like this:
We want to pass the environment name into the Sentry client config:
When putting this code into
sentry.client.config.js
, we end up getting the app broken because it runs in the browser before the config has loaded.I tried in our root layout (Next JS App router) to direct that the config script be loaded with strategy="beforeInteractive", which results in the client side hydration waiting for the config to be ready as expected, but not the Sentry initialisation.
The only way I've been able to figure out how to get around this is to make an empty
sentry.client.config.js
file (deleting it causes a build error) and create a client layout component like this:It works fine but does feel a bit "hacky" so I'm just wondering is there a better way, other than injecting environment variables at build time instead of run time?
Beta Was this translation helpful? Give feedback.
All reactions