feat(nextjs): Support assetPrefix option#6388
Merged
lobsterkatie merged 8 commits intomasterfrom Dec 2, 2022
Merged
Conversation
80b9957 to
059a9eb
Compare
Contributor
size-limit report 📦
|
Base automatically changed from
kmclb-nextjs-make-prefix-loader-generic
to
master
December 2, 2022 09:44
lforst
approved these changes
Dec 2, 2022
Contributor
lforst
left a comment
There was a problem hiding this comment.
Nice investigative work on how the stack traces come together!
668bf59 to
0f1f159
Compare
0f1f159 to
720a75f
Compare
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.
This adds support support for the nextjs
assetPrefixoption to the nextjs SDK. Currently, if users set this option, it changes the filepaths in their client-side stacktraces in a way not reflected in their release artifact names, causing sourcemaps not to work. This fixes that by usingRewriteFramesto modify the stacktrace filepaths so that they'll match the release artifacts.Notes:
Initial work on this was done by @tomas-c in fix(nextjs): handle assetPrefix #6241. (Thanks, @tomas-c!) The approach taken there was to change the way the client-side release artifacts are named, rather than to change the filenames in the stacktrace as is done here. After discussions with @lforst, I decided to take this approach because it's more consistent with what we already do on the server side. There, we use
RewriteFrames, and we mutate the filepaths to start withapp:///_next. This mirrors that for the client side.In the process of working on this, I discovered that we currently have a bug, caused by the way we handle the
basePathoption when naming release artifacts, including it at the beginning of all artifact names. Unfortunately, it's not included in stacktrace filenames, so this is a mistake.On the server side, this makes the stacktrace filenames and the artifact filenames not match, meaning sourcemaps for people using that option are currently broken for all sever-side errors. (The reason this hasn't been more obvious is that in the node SDK, we harvest context lines at capture time, rather than relying on sourcemapping to provide them. Also, server-side built code is transpiled but not bundled or mangled, making even un-sourcemapped code much easier to read than it is on the browser side of things.)
On the browser side, it doesn't break sourcemaps, but only because it turns out that nextjs copies
basePathover intoassetPrefixif a user provides the former but not the latter. As mentioned,basePathdoesn't appear in stacktrace filepaths, butassetPrefixdoes, which is what led us to think was working.To fix this, this PR stops including
basePathin artifact filenames. As a result, on both the server-side and client-side, all artifact filenames are now of the form~/_next/..., rather than some looking like that but others looking like~/basePathValue/_next/....Part of the work here was figuring out how
distDir,basePath, andassetPrefixinteract, and where they show up in stacktrace filepaths. Just so it's written down somewhere, the answer is:basePath- Never shows up in stacktrace filepaths, except insofar as it's copied intoassetPrefixif it's set andassetPrefixisn't, in which caseassetPrefixacts like it's path-only.distDir- Server-side stacktrace filepaths are of the form<pathToProjectDir>/<distDir>/server/...(or<pathToProjectDir>/<distDir>/serverless/...). Example:/path/on/host/machine/someDistDir/server/....assetPrefix- IfassetPrefixis a full url, client-side stacktrace filepaths are of the form<assetPrefixHost>/<assetPrefixPath>/_next/static/.... IfassetPrefixjust a path, stacktrace filepaths are of the form<host>/<assetPrefixPath>/_next/static/.... Examples: http://some.assetPrefix.host/some/assetPrefix/path/_next/...` andhttp://some.normal.domain/some/assetPrefix/path/_next/....Fixes #4174.