Skip to content
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

fix: sourcemap error with plugin-react #5563

Closed
wants to merge 2 commits into from
Closed
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
9 changes: 9 additions & 0 deletions packages/plugin-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
let skipFastRefresh = opts.fastRefresh === false
let skipReactImport = false

// The dir where pre-bundled deps is stored
let cacheDir: string

const useAutomaticRuntime = opts.jsxRuntime !== 'classic'

const userPlugins = opts.babel?.plugins || []
Expand All @@ -78,6 +81,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
})
isProduction = config.isProduction
skipFastRefresh ||= isProduction || config.command === 'build'
cacheDir = config.cacheDir as string

const jsxInject = config.esbuild && config.esbuild.jsxInject
if (jsxInject && importReactRE.test(jsxInject)) {
Expand Down Expand Up @@ -107,6 +111,11 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
filepath.match(fileExtensionRE) ||
[]

// Pre-bundle deps should not be transformed there. #5438
if (id.startsWith(cacheDir)) {
return
}

if (/\.(mjs|[tj]sx?)$/.test(extension)) {
const plugins = [...userPlugins]

Expand Down
5 changes: 3 additions & 2 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,8 @@ export function combineSourcemaps(
const useArrayInterface =
sourcemapList.slice(0, -1).find((m) => m.sources.length !== 1) === undefined
if (useArrayInterface) {
map = remapping(sourcemapList, () => null, true)
// We cann't exclude sourcesContent there. #5438
map = remapping(sourcemapList, () => null, false)
} else {
map = remapping(
sourcemapList[0],
Expand All @@ -531,7 +532,7 @@ export function combineSourcemaps(
return { ...nullSourceMap }
}
},
true
false
)
}
if (!map.file) {
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

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