fix(nextjs): Move userNextConfig.sentry
to closure
#5473
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
h/t to @mitchheddles for the research and initial idea - thanks!
As of vercel/next.js#38498, nextjs now warns (voluminously) if the config exported from
next.config.js
contains properties it doesn't recognize, including thesentry
property we've been having people use to do things like disable the webpack plugin. In order to prevent these warnings, the final config returned fromwithSentryConfig
must not have such a property, so this deletes the property from theuserNextConfig
object before returning it.If we were to stop there, the warning would be gone, but so would the data
userNextConfig.sentry
contains. (This is true even if we runconstructWebpackConfigFunction
before doing the deletion, because the place we need theuserNextConfig.sentry
data is not inconstructWebpackConfigFunction
itself but in the function it returns. By the time that function is called by nextjs, the deletion will already have gone through and the data will be gone unless we keep a reference to it elsewhere.) Therefore, in order to allow the returned function to retain access theuserNextConfig.sentry
data, this captures it before it's deleted and passes it toconstructWebpackConfigFunction
, where it lives in a closure around the returned function.fixes #5449