-
-
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: sourcemap error with plugin-react #5563
Conversation
@Niputi @bluwy @Shinigami92 @patak-js PTAL. I think it will be a serious issue because the plugin will use babel to transform pre-bundled result which is very large.And there will be a lot of error messages in the console, such as
This is bound to affect DX very much. |
tests need to be passing. |
6725937
to
14a7985
Compare
ok,i will adjust to pass the test. @aleclarson PTAL |
14a7985
to
888241a
Compare
This issue has existed for more than a week. And the 1.0.7 version was proposed at the time, and now the 1.1.0 beta version, the problem still exists.I will be very grateful if I can help solve this problem. |
888241a
to
455cc7e
Compare
455cc7e
to
16d0833
Compare
FWIW I've encountered this sourcemap warning too in I've been debugging this myself to no avail, but I think Vite should work even if we return sourcemaps during the prebundling phase. Maybe that's the long term solution, but I'd be interested to see if anyone knows why, instead of skipping transformation in prebundling. |
It’s not just the sourcemap problem. Using babel to transform the pre-bundled dep in this plugin is a very performance-consuming and unnecessary thing originally.And The page load time will be very long. This is one of the reasons why I proposed this solution. |
Regarding the problem of souremap, I very much agree with you, and I feel the same way. I think that Vite should also be able to work even when additional sourcemaps are added. I will try to find a way to solve it inside vite.That's another matter. |
It is necessary, because we want dev to match production as closely as possible, and that means applying the "automatic JSX runtime" transform to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the right fix. We should instead make sure the sourcemaps generated by pre-bundling don't include sources like dep:react
or we should tolerate such sources wherever sourcemaps are processed by Vite.
If you really try it in a real project, you will find that using babel transfom will be very slow, and in general projects there will be a large number of 500 KB pre-bundle results (this will also appear a series of waring about babel, which confused the users). See detail in #5438. [BABEL] Note: The code generator has deoptimised the styling of /Users/sanyuan/react-project/node_modules/.vite/react-dom.js?v=768d5ed4 as it exceeds the max of 500KB. These large results are packaged with babel one by one, and it is inevitable that the page will take twenty seconds or more to open. This is horrible. I don’t think it’s a must to use babel in the development phase, or it can’t be used as a built-in default operation. |
We need to make some balance between DX and development-production environment consistency. In this more extreme situation, I think we need to give priority to DX, because fast is originally a core advantage of Vite. To use babel to transform deps, I think it can be left to the user to configure and decide which deps are needed transforming, instead of all the dependency code transformed by default. |
55c8609
to
e689446
Compare
@bluwy I have found out why additional sourcemap couldn't work in vite.In the logic of combineSourceMap, remapping function is called, but the sourcesContent is excluded in the end, which leads to the original file not being found in vite. I have updated the code. |
Thanks for looking into this! I tested it locally again and it seems to still report the same sourcemap warnings. Maybe it's because that Svelte generates a relative source file name, but I'll try to look into that myself. Regarding the remapping change, I'm not a sourcemap wizard so I can't tell if it's a desirable change or not 😅 |
I haven't tried Svelte, but this solution can solve the sourcemap warning problem under the React project. I try to solve it in svelte, maybe I can mention another PR. |
I'm experiencing this now in a monolith Rails app with React and some legacy haml views, scss and Svelte. Before this started happening I was able to see the browser load in about 20 seconds. Now it takes 60-90 seconds before the browser actually loads. I spent a significant amount of time getting us switched over to Vite and now my team is less then thrilled about this behavior and wasn't able to experience the quick load times like I was. The warnings are alarming and the time to wait for the browser to load is almost not acceptable for most of my team. Thank you for looking into this! |
@aleclarson PTAL |
@antfu PTAL |
@patak-js PTAL.It seems a serious bug. |
Description
Fix sourcemap error when using @vitejs/plugin-react,see details in #5438, #5562
Additional context
The product of pre-bundle is incorrectly transformed by babel in plugin-react.This led to a series of unpredictable sourcemap problems, because this plugin will generate some sourcemaps which will be push into vite's sourcemapChain and combined after transform hook.
The reason why the
1.0.6
plugin version does not have this problem is because of therequest of pre-bundle deps will carry the querystring suffix of BrowserHash, thus skipping the transform process of react:babel. But in 1.0.7 version the plugin filters out the querystring suffix, so that the pre-bundle result such as
/xxx/node_modules/.vite/react.js
also enters the transform of babel which is unespect.Now the solution is as follows:
remapping
process.It can be solved by including sourcesContent after remapping if additional soucemap is added after transform hook.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).