ref(nextjs): Use loader to set RewriteFrames helper value#5445
Merged
lobsterkatie merged 6 commits intomasterfrom Jul 25, 2022
Merged
ref(nextjs): Use loader to set RewriteFrames helper value#5445lobsterkatie merged 6 commits intomasterfrom
RewriteFrames helper value#5445lobsterkatie merged 6 commits intomasterfrom
Conversation
f6a6180 to
92fcf90
Compare
Lms24
approved these changes
Jul 22, 2022
| type LoaderOptions = { | ||
| distDir: string; | ||
| }; | ||
| // TODO Use real webpack types |
Member
There was a problem hiding this comment.
Is this gonna be done in a follow-up PR?
Member
Author
There was a problem hiding this comment.
Probably? Maybe? It's low priority, and slightly complicated by the need to be compatible with both webpack 4 and webpack 5. Not a blocker at the moment.
lobsterkatie
added a commit
that referenced
this pull request
Jul 28, 2022
…5479) In #5445, a change was made to the way the global `RewriteFrames` helper value is handled. Specifically, setting the default value (using the `||` operator) was moved to the place where the value is set rather than where it's retrieved. But if something goes wrong and for whatever reason the value never gets set globally, it now causes errors when the value is later used, because it has nothing to default to. This fixes that by restoring the default value to the old location, so that when it's used, it will never be undefined. Fixes #5478.
Closed
43 tasks
Contributor
|
ref: #5505 |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Ref: #5505
In order to work, in the nextjs SDK our server-side
RewriteFramesintegration needs to know the name of the directory into which the app is built. While that information is readily available at build time, it isn't at runtime, so we adjust the webpack config to inject a global variable with the correct value in before the the injectedSentry.init()call fromsentry.server.config.jswherever we inject that `Sentry.init().Currently, this is done by creating a temporary file with the relevant code and adding it to the relevant pages'
entryvalue along withsentry.server.config.js. This works, but has its downsides, and is a fair amount of machinery just to add a single line of code.This injects the same line of code using a loader, which is really just a transformation function for the code from matching files. In this case, we're modifying
sentry.server.config.jsitself, so that by the time it's added to various pages' entry points, it already contains the relevant code. Since we don't know what the value will be ahead of time, there's a template, which the loader then populates before injecting the new code.But how is that any less machinery?, you might ask. All of that, still for just one line of code? Honestly, it's not. But in the quest to improve parameterization of transactions names, we're going to be adding a loader in any case. Adding the
RewriteFramesvalue thus provides the perfect proof of concept, precisely because it's so simple, letting us get the loader working separate from all of the other changes that work will entail.Notes:
distDirfrom retrieval-of-the-value time to storage-of-the-value time, because using a loader necessarily stringifies everything, meaningundefinedwas turning into the string'undefined', preventing the default from getting picked up.Fixes #4684