fix(react): sourcemap incorrect warning and classic runtime sourcemap#9006
Conversation
✅ Deploy Preview for vite-docs-main canceled.
|
|
Had a wild idea if we append the React import at the end instead so we don't have to generate sourcemaps, since ES import hoists, but that sounds dangerous (or is it) 😄 |
|
That's smart. I thought this might not work, but actually it seems to work. // foo.mjs
console.log(foo) // 'foo'
await new Promise(resolve => setTimeout(resolve, 100))
console.log(foo) // 'foo'
import { foo } from './react.mjs'// react.mjs
await new Promise(resolve => setTimeout(resolve, 100))
export const foo = 'foo'It seems there is some issues when ESM -> CJS transform is used, but since we don't do that it won't be a issue? Another thing we may need to consider is sideeffects. import './a.js' // depends on sideeffect of react but doesn't import reactIf we prepend |
|
Yeah I don't think we'd hit the ESM->CJS issue since the TypeScript's compiler isn't used in Vite. I think the trick should mostly work but cant tell for sure until we get some user-testing. I'd still be happy to proceed with this PR to be on the safe side though. |
|
We can explore this in v4, lets try to keep things stable now 😄 |
Description
From plugin-react 2.0.0-beta.1, the following warning was happening. This PR fixes that.
Reproduction: https://stackblitz.com/edit/vitejs-vite-g4zebx
Also this PR fixes classic runtime sourcemap which was incorrect in some cases.
refs #8676
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).