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(react): sourcemap incorrect warning and classic runtime sourcemap #9006

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/plugin-react/src/index.ts
Expand Up @@ -278,7 +278,8 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
if (shouldSkip) {
// Avoid parsing if no plugins exist.
return {
code
code,
map: null
sapphi-red marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
7 changes: 7 additions & 0 deletions playground/react-sourcemap/App.jsx
@@ -0,0 +1,7 @@
function App() {
return <div>foo</div>
}

console.log('App.jsx') // for sourcemap

export default App
7 changes: 7 additions & 0 deletions playground/react-sourcemap/__tests__/react-sourcemap.spec.ts
@@ -0,0 +1,7 @@
import { isBuild, serverLogs } from '~utils'

test.runIf(isBuild)('should not output sourcemap warning', () => {
serverLogs.forEach((log) => {
expect(log).not.toMatch('Sourcemap is likely to be incorrect')
})
})
2 changes: 2 additions & 0 deletions playground/react-sourcemap/index.html
@@ -0,0 +1,2 @@
<div id="app"></div>
<script type="module" src="main.jsx"></script>
9 changes: 9 additions & 0 deletions playground/react-sourcemap/main.jsx
@@ -0,0 +1,9 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.jsx'

ReactDOM.createRoot(document.getElementById('app')).render(
React.createElement(App)
)

console.log('main.jsx') // for sourcemap
18 changes: 18 additions & 0 deletions playground/react-sourcemap/package.json
@@ -0,0 +1,18 @@
{
"name": "test-react-sourcemap",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@vitejs/plugin-react": "workspace:*"
}
}
11 changes: 11 additions & 0 deletions playground/react-sourcemap/vite.config.ts
@@ -0,0 +1,11 @@
import react from '@vitejs/plugin-react'
import type { UserConfig } from 'vite'

const config: UserConfig = {
plugins: [react()],
build: {
sourcemap: true
}
}

export default config
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

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