Skip to content

Commit b589685

Browse files
authored
fix(nextjs): Rewrite abs_path frames (#7619)
1 parent a2bd1e0 commit b589685

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

packages/nextjs/src/client/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,26 @@ function addClientIntegrations(options: BrowserOptions): void {
7777
// Turn `<origin>/<path>/_next/static/...` into `app:///_next/static/...`
7878
iteratee: frame => {
7979
try {
80-
const { origin } = new URL(frame.filename as string);
81-
frame.filename = frame.filename?.replace(origin, 'app://').replace(assetPrefixPath, '');
80+
const { origin: absPathOrigin } = new URL(frame.abs_path as string);
81+
const { origin: filenameOrigin } = new URL(frame.filename as string);
82+
frame.abs_path = frame.abs_path?.replace(absPathOrigin, 'app://').replace(assetPrefixPath, '');
83+
frame.filename = frame.filename?.replace(filenameOrigin, 'app://').replace(assetPrefixPath, '');
8284
} catch (err) {
8385
// Filename wasn't a properly formed URL, so there's nothing we can do
8486
}
8587

88+
// We need to URI-decode the filename because Next.js has wildcard routes like "/users/[id].js" which show up as "/users/%5id%5.js" in Error stacktraces.
89+
// The corresponding sources that Next.js generates have proper brackets so we also need proper brackets in the frame so that source map resolving works.
8690
if (frame.filename && frame.filename.startsWith('app:///_next')) {
87-
// We need to URI-decode the filename because Next.js has wildcard routes like "/users/[id].js" which show up as "/users/%5id%5.js" in Error stacktraces.
88-
// The corresponding sources that Next.js generates have proper brackets so we also need proper brackets in the frame so that source map resolving works.
8991
frame.filename = decodeURI(frame.filename);
9092
}
93+
if (frame.abs_path && frame.abs_path.startsWith('app:///_next')) {
94+
frame.abs_path = decodeURI(frame.abs_path);
95+
}
9196

9297
if (
93-
frame.filename &&
94-
frame.filename.match(
98+
frame.abs_path &&
99+
frame.abs_path.match(
95100
/^app:\/\/\/_next\/static\/chunks\/(main-|main-app-|polyfills-|webpack-|framework-|framework\.)[0-9a-f]+\.js$/,
96101
)
97102
) {

0 commit comments

Comments
 (0)