Skip to content

Commit b6fa6be

Browse files
authored
Handle URL-encoded Turbopack client chunks when resolving source maps (#71274)
When using Turbopack, after a client-side navigation, the source map for a client chunk might be requested using an URL-encoded pathname, e.g. `/_next/static/chunks/%5Bproject%5D__48591b._.js` instead of `/_next/static/chunks/[project]__48591b._.js`. When trying to look up the source map this would fail with: ``` Failed to get source map: [Error: chunk/module is missing a sourcemap] { code: 'GenericFailure' } ``` To fix this, we're now decoding the filename. ## Test Plan - start `pnpm next dev --turbo test/development/app-dir/source-mapping` - go to `http://localhost:3000` - click on "client component page" link - open React DevTools Components view - select `Form` - click on `bar()` action (requires version 6.0) - you should end up in the the `actions.ts` source file
1 parent 61c9988 commit b6fa6be

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/next/src/client/components/react-dev-overlay/server/middleware-turbopack.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ export function getSourceMapMiddleware(project: Project, distDir: string) {
171171

172172
try {
173173
if (filename.startsWith('/_next/static')) {
174-
filename = path.join(distDir, filename.replace(/^\/_next\//, ''))
174+
filename = path.join(
175+
distDir,
176+
// /_next/static/chunks/%5Bproject%5D... => static/chunks/[project]...
177+
decodeURIComponent(filename.replace(/^\/_next\//, ''))
178+
)
175179
}
176180

177181
const sourceMapString = await project.getSourceMap(filename)

0 commit comments

Comments
 (0)