-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
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 react If 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
).