-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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: missing js sourcemaps with rewritten imports broke debugging (#7767) #9476
fix: missing js sourcemaps with rewritten imports broke debugging (#7767) #9476
Conversation
Move the dummy sourcemap generation out of `transformStableResult()` so it has no impact on doing the transformations. Eliminate need for `highres: true` making generation faster and sourcemaps smaller when the mappings are superficial.
I tested with VSCode but this didn't work. Does this work with WebStorm or other IDE/code editors? |
I'm not using VSCode, so I did not test it before, but I did now compare the behaviour with PhpStorm (which will serve as my benchmark for all InteliJ IDEs). What works in both:
Where things divert is:
Long story short I think from this point this issue should be raised with VSCode team. They have to look into why VSCode cannot understand that now a new file seen by the Browser is mapped to the same source as another file was before and why they show the same breakpoint being hit twice in two different versions of the files. My assumption is that it is an IDE issue, whereas as suggested by JetBrains the issue effecting InteliJ IDEs was that the sourcemaps were missing and with that fixed it works fine in PhpStorm (and we can assume in their other IDEs as well). EDIT: Additional notesI've found that if the debugging browser is closed and opened again VSCode resolves to the correct file once again without Vite dev restarted, so it is kind of like an issue between the broswer and the IDE agreeing on which file seen by the browser resolves to which file seen by the IDE. Not much to do with Vite. Maybe as a workaround Vite could force the browser to not only load the new version of the file under a new URL, but also to load e.g. an empty file from the previous URL so there would be no more than one file at one time being resolved to the same source. But that would be kind of like adapting Vite to a bug in VSCode. Would not hurt probably, but it really should be a fix in the way the IDE interprets the information from the Browser. Still I think the fact that Browser debugging in IDE works fine before HMR with this patch both in VSCode and InteliJ is a nice step forward. PS: Did not try in other IDEs, I don't even know others. 🤷♂️ |
The issue did not affect the testing as the loaded JS file was not executed, only fixed for the sake of correctness.
@sapphi-red: Could you tell more about what is not working for you? Probably it is something other than the issues I've found it may worth looking into more... I've found another interesting aspect: If imports in the original source are spread to multiple lines, it may interfere with this solution, but I'll check that and probably even if this is the case the solution would be to simply keep imports in as many lines as they are in the source so we could still go ahead with low cost dummy sourcemaps while at the same time hopefully fix this kind of problem as well. Will try to reproduce, examine and report back soon. |
Thank you for testing it and the detailed report!
This was what I was talking about. I was testing around VSCode's debugger with Vite and found that setting {
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome",
"request": "launch",
"type": "pwa-chrome",
"url": "http://localhost:5173",
"webRoot": "${workspaceFolder}",
"enableContentValidation": false
}
]
} I think this solution is most ideal. This way Vite won't need to change anything and of course it won't have any perf implications. |
Hello, |
I don't think so. They apparently wish to stick to the standard on this one: if a file is served from a location that the IDE cannot correspond with the development folder, because they have different contents, they expect a SourceMap to be present. See the related issue here: https://youtrack.jetbrains.com/issue/WEB-55544 Basically it is a "won't fix" / "feature request" to allow different files to be debugged as if they were the same.
Since Vite rewrites imports, and imports may be formatted in source code to spread multiple lines a proper SourceMap will still be needed even in VSCode in those cases, because as soon as the line numbers shift (as Vite rewrites the imports) a simple file path mapping won't be enough for proper debugging. I know I said moths ago I'll check this, but had other things to do. Now I've managed to get back on this, so will look into it. Regarding performance we could make this optional. Something like a new setting under Server Options called *: Vite without this patch already generates full blown sourcemaps:
So long story short, we are talking about an overhead for Moreover the changes in this PR also attempt to further reduce the sourcemapping overhead by only generating the Right now I'm using my patched Vite for development and debugging works great. I see no visible performance impact whatsoever and it is such an ease to be able to properly debug in the IDE for many cases that had issues previously. Please let me know your thoughts, because I don't find the performance argument to be significant based on the above. |
Compatibility was broken with fix vitejs#9914 but also we don't need and don't want to add dummy sourcemaps to HMR JS requests.
I just wanted to explore a way not to add an additional perf cost. I agree the implication won't be significant.
BTW Vite avoids the line numbers to be shifted when rewriting imports. So this won't happen. (If it does that's a bug.) |
Thank you! I hope it'll go through! 🤞
That's great news! Maybe I saw it happening some time with v2, but maybe I was mistaken. Anyway, happy to hear that! |
Ah, yeah, in v2, there was some and fixed in v3. |
…nses Based on the [suggestion](vitejs#9476 (comment)) of [sapphi-red](https://github.com/sapphi-red)
In the last meeting, we decided that we can go without an option if there aren't perf implications. I tested this out with some projects and didn't find differences in that point. So I think it's fine. |
…tejs#7767) (vitejs#9476) Co-authored-by: sapphi-red <[email protected]>
@Enzojz Answered here: #7767 (comment) |
By the way, I can see it is merged in 4.0.0-alpha.6. Has release cycle for v3.x ended, or would this still land in v3 as well? |
…debugging (vitejs#7767) (vitejs#9476)" This reverts commit 3fa96f6.
Has just replied there. |
Description
Supposedly fixes #7767
refs vitejs/vite-plugin-react#23 #5834
Additional context
See detailed discussion under the related issue
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes vitejs/vite#123
).