-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
fix: Ensure we never mutate options passed to init
#9162
Conversation
In various places we mutate the `options` passed to `init()`, which is a) not a great pattern and b) may break if users pass in frozen or similar objects (for whatever reason).
size-limit report 📦
|
applyTunnelRouteOption(options); | ||
buildMetadata(options, ['nextjs', 'react']); | ||
const opts = { | ||
environment: getVercelEnv(true) || process.env.NODE_ENV, |
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.
Hey, @mydea !
Maybe I don't fully understand how it's supposed to work, but this breaks our app on update, cause we used to pass environment in options in sentry.client.config.ts, and now it seems to be ignored? It falls back to getVercelEnv in our case, which calls process, which doesn't exist in browser. I am not sure if it's a cause or maybe we're using it wrong and this code should never reach client?
We're getting Uncaught ReferenceError: process is not defined here:
Downgrading to 7.73.0, before this change, fixes it for us.
Any advise?
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.
We object spread in the options, so an explicitly set environment
should override what the sdk attempts to set.
const opts = {
environment: getVercelEnv(true) || process.env.NODE_ENV,
// environment defined on passed in options should override above
...options
}
Could you please open a GH issue with a minimal reproduction so we can help debug further? Thanks!
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.
Yeah, it does override it potentially, but it fails before cause process
doesn't exist in client. I am on the go now, will try to create an issue later. Thank you!
In various places we mutate the
options
passed toinit()
, which is a) not a great pattern and b) may break if users pass in frozen or similar objects (for whatever reason).I also normalized this to ensure a passed in
_metadata.sdk
always takes precedent (we had this in most places, but not all).Closes #9155