From 69d0e6082caa5b3130c9b0b28de9efd2ec7e5773 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Tue, 13 Sep 2022 23:42:09 +0200 Subject: [PATCH] Passing down original sourcemap for flight client loader (#40508) Consume the original sourcemap in flight client loader if there's any, to avoid source map is generated based on the module proxy which make debugging hard Testing with adding `debugger` in layout router, screenshot: image --- .../webpack/loaders/next-flight-client-loader/index.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/next/build/webpack/loaders/next-flight-client-loader/index.ts b/packages/next/build/webpack/loaders/next-flight-client-loader/index.ts index 6c27a5a49f2dfbd..f36ed00d6dfbf88 100644 --- a/packages/next/build/webpack/loaders/next-flight-client-loader/index.ts +++ b/packages/next/build/webpack/loaders/next-flight-client-loader/index.ts @@ -16,12 +16,14 @@ function containsPath(parent: string, child: string) { export default async function transformSource( this: any, - source: string -): Promise { + source: string, + map: any +) { if (typeof source !== 'string') { throw new Error('Expected source to have been transformed to a string.') } + const callback = this.async() const appDir = path.join(this.rootContext, 'app') const isUnderAppDir = containsPath(appDir, this.resourcePath) const filename = path.basename(this.resourcePath) @@ -50,5 +52,7 @@ export default async function transformSource( const { createProxy } = require("next/dist/build/webpack/loaders/next-flight-client-loader/module-proxy")\n module.exports = createProxy(${JSON.stringify(this.resourcePath)}) ` - return output + // Pass empty sourcemap + callback(null, output, map) + return }