-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[sourcemaps] Ensure codeframe when calling Client Functions from Server #81918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,9 @@ | ||||||||
import type { NormalModule, webpack } from 'next/dist/compiled/webpack/webpack' | ||||||||
import type { | ||||||||
javascript, | ||||||||
LoaderContext, | ||||||||
NormalModule, | ||||||||
webpack, | ||||||||
} from 'next/dist/compiled/webpack/webpack' | ||||||||
import { RSC_MOD_REF_PROXY_ALIAS } from '../../../../lib/constants' | ||||||||
import { | ||||||||
BARREL_OPTIMIZATION_PREFIX, | ||||||||
|
@@ -8,10 +13,7 @@ import { warnOnce } from '../../../../shared/lib/utils/warn-once' | |||||||
import { getRSCModuleInformation } from '../../../analysis/get-page-static-info' | ||||||||
import { formatBarrelOptimizedResource } from '../../utils' | ||||||||
import { getModuleBuildInfo } from '../get-module-build-info' | ||||||||
import type { | ||||||||
javascript, | ||||||||
LoaderContext, | ||||||||
} from 'next/dist/compiled/webpack/webpack' | ||||||||
import { ModuleFilenameHelpers } from 'next/dist/compiled/webpack/webpack' | ||||||||
|
||||||||
type SourceType = javascript.JavascriptParser['sourceType'] | 'commonjs' | ||||||||
|
||||||||
|
@@ -72,6 +74,7 @@ export default function transformSource( | |||||||
prefix = `/* __rspack_internal_rsc_module_information_do_not_use__ ${rscModuleInformationJson} */\n` | ||||||||
source = prefix + source | ||||||||
} | ||||||||
prefix += `// This file is generated by the Webpack next-flight-loader.\n` | ||||||||
|
||||||||
// Resource key is the unique identifier for the resource. When RSC renders | ||||||||
// a client module, that key is used to identify that module across all compiler | ||||||||
|
@@ -144,7 +147,28 @@ ${JSON.stringify(ref)}, | |||||||
} | ||||||||
} | ||||||||
|
||||||||
return this.callback(null, esmSource, sourceMap) | ||||||||
const compilation = this._compilation! | ||||||||
const originalSourceURL = ModuleFilenameHelpers.createFilename( | ||||||||
module, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already informed the Rspack team but haven't heard back yet. |
||||||||
{ | ||||||||
moduleFilenameTemplate: | ||||||||
'webpack://[namespace]/[resource-path]/__nextjs-internal-proxy.mjs', | ||||||||
namespace: '_N_E', | ||||||||
}, | ||||||||
{ | ||||||||
requestShortener: compilation.requestShortener, | ||||||||
chunkGraph: compilation.chunkGraph, | ||||||||
hashFunction: compilation.outputOptions.hashFunction, | ||||||||
} | ||||||||
) | ||||||||
|
||||||||
return this.callback(null, esmSource, { | ||||||||
version: 3, | ||||||||
sources: [originalSourceURL], | ||||||||
// minimal, parseable mappings | ||||||||
mappings: 'AAAA', | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe explain why we can get away with emitting no mappings? AFAIU the reasoning is sth like this
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (also personally i wouldn't mind moving this into a helper like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not an empty sourcemap. It's just the minimal amount of mappings you need for it to be parseable by the sourcemap parsers we encounter. I need to think more about a sensible explainer to justify the abstraction. Until then I rather have it inline to avoid spreading an abstraction that may be incorrect. |
||||||||
sourcesContent: [esmSource], | ||||||||
}) | ||||||||
} else if (assumedSourceType === 'commonjs') { | ||||||||
let cjsSource = | ||||||||
prefix + | ||||||||
|
@@ -153,7 +177,29 @@ const { createProxy } = require("${MODULE_PROXY_PATH}") | |||||||
|
||||||||
module.exports = createProxy(${stringifiedResourceKey}) | ||||||||
` | ||||||||
return this.callback(null, cjsSource, sourceMap) | ||||||||
|
||||||||
const compilation = this._compilation! | ||||||||
const originalSourceURL = ModuleFilenameHelpers.createFilename( | ||||||||
module, | ||||||||
{ | ||||||||
moduleFilenameTemplate: | ||||||||
'webpack://[namespace]/[resource-path]/__nextjs-internal-proxy.cjs', | ||||||||
namespace: '_N_E', | ||||||||
}, | ||||||||
{ | ||||||||
requestShortener: compilation.requestShortener, | ||||||||
chunkGraph: compilation.chunkGraph, | ||||||||
hashFunction: compilation.outputOptions.hashFunction, | ||||||||
} | ||||||||
) | ||||||||
|
||||||||
return this.callback(null, cjsSource, { | ||||||||
version: 3, | ||||||||
sources: [originalSourceURL], | ||||||||
// minimal, parseable mappings | ||||||||
mappings: 'AAAA', | ||||||||
sourcesContent: [cjsSource], | ||||||||
}) | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We completely replaced the original source so the original sourcemap can be discarded.