Skip to content

Alternate bundler: fix react refresh and adjust sourcemap #77875

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

Merged
merged 4 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"@opentelemetry/api": "1.4.1",
"@picocss/pico": "1.5.10",
"@rspack/core": "1.3.2",
"@rspack/plugin-react-refresh": "1.1.0",
"@rspack/plugin-react-refresh": "1.2.0",
"@svgr/webpack": "5.5.0",
"@swc/cli": "0.1.55",
"@swc/core": "1.9.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-rspack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"types": "index.d.ts",
"dependencies": {
"@rspack/core": "1.3.2",
"@rspack/plugin-react-refresh": "1.1.0",
"@rspack/plugin-react-refresh": "1.2.0",
"react-refresh": "0.12.0"
}
}
20 changes: 13 additions & 7 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,15 +671,19 @@ export default async function getBaseWebpackConfig(
'...',
]

const reactRefreshEntry = isRspack
? getRspackReactRefresh().entry
: require.resolve(
`next/dist/compiled/@next/react-refresh-utils/dist/runtime`
)

const clientEntries = isClient
? ({
// Backwards compatibility
'main.js': [],
...(dev
? {
[CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH]: require.resolve(
`next/dist/compiled/@next/react-refresh-utils/dist/runtime`
),
[CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH]: reactRefreshEntry,
[CLIENT_STATIC_FILES_RUNTIME_AMP]:
`./` +
path
Expand All @@ -705,9 +709,7 @@ export default async function getBaseWebpackConfig(
? {
[CLIENT_STATIC_FILES_RUNTIME_MAIN_APP]: dev
? [
require.resolve(
`next/dist/compiled/@next/react-refresh-utils/dist/runtime`
),
reactRefreshEntry,
`./` +
path
.relative(
Expand Down Expand Up @@ -1902,7 +1904,11 @@ export default async function getBaseWebpackConfig(
isClient &&
(isRspack
? // eslint-disable-next-line
new (getRspackReactRefresh() as any)({ injectLoader: false })
new (getRspackReactRefresh() as any)({
injectLoader: false,
injectEntry: false,
overlay: false,
})
: new ReactRefreshWebpackPlugin(webpack)),
// Makes sure `Buffer` and `process` are polyfilled in client and flight bundles (same behavior as webpack 4)
(isClient || isEdgeServer) &&
Expand Down
12 changes: 1 addition & 11 deletions packages/next/src/build/webpack/config/blocks/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export const base = curry(function base(
if (ctx.isDevelopment) {
if (process.env.__NEXT_TEST_MODE && !process.env.__NEXT_TEST_WITH_DEVTOOL) {
config.devtool = false
} else if (process.env.NEXT_RSPACK) {
config.devtool = 'source-map'
} else {
// `eval-source-map` provides full-fidelity source maps for the
// original source, including columns and original variable names.
Expand All @@ -51,14 +49,6 @@ export const base = curry(function base(
(ctx.productionBrowserSourceMaps && ctx.isClient)
) {
config.devtool = 'source-map'
config.plugins ??= []
config.plugins.push(
new DevToolsIgnorePlugin({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate with the below one

// TODO: eval-source-map has different module paths than source-map.
// We're currently not actually ignore listing anything.
shouldIgnorePath,
})
)
} else {
config.devtool = false
}
Expand All @@ -69,7 +59,7 @@ export const base = curry(function base(
}

config.plugins ??= []
if (config.devtool === 'source-map') {
if (config.devtool === 'source-map' && !process.env.NEXT_RSPACK) {
config.plugins.push(
new DevToolsIgnorePlugin({
shouldIgnorePath,
Expand Down
7 changes: 6 additions & 1 deletion packages/next/src/shared/lib/get-rspack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ export function getRspackReactRefresh() {
gateCanary()
try {
// eslint-disable-next-line import/no-extraneous-dependencies
return require('@rspack/plugin-react-refresh')
const plugin = require('@rspack/plugin-react-refresh')
const entry = require.resolve(
'@rspack/plugin-react-refresh/react-refresh-entry'
)
plugin.entry = entry
return plugin
} catch (e) {
if (e instanceof Error && 'code' in e && e.code === 'MODULE_NOT_FOUND') {
throw new Error(
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading