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.
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.
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.
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
optionspassed 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.sdkalways takes precedent (we had this in most places, but not all).Closes #9155