-
-
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: breakpoints in JS not working #13514
fix: breakpoints in JS not working #13514
Conversation
Run & review this pull request in StackBlitz Codeflow. |
Nice! If this isn't a regression for VS Code, I think we can merge it and get some mileage from users in the 4.4 beta. One thing I see is that the source is being applied to some files where it doesn't help. I imagine it isn't hurting though, but we could try to apply it only if the
In the second case, it points to a real file but adding a breakpoint isn't useful. Still, I don't think it would hurt having the comment there. About 1., should it point to |
I know this sounds obvious and like a great solution and @jaro-sevcik and I discussed this as well yesterday and whether we should recommend this as a fix. However, this isn't going to work as you expect it to work (with Chrome), because While this is more of an implementation detail of V8/Chrome, and I think we could also change it over time (although the specified behavior for |
It's a partial regression. Without this PR, the breakpoints work if that file is not changed. But with this PR, the breakpoints don't work even if that file is not changed.
I see. To generate an identity source map, Vite will have to tokenize the content of the file and generate the mappings field. Or skip the tokenization and generate the mapping field with the every character in the file. Is there a better way than this? |
I'd use a naive approach and just generate a mapping for every whitespace/word boundary (poor mans tokenization). |
3e6073c
to
cc70dd4
Compare
I updated the PR to inject I tested this with Chrome and Firefox and VSCode debugger on Windows. It worked fine. |
packages/vite/rollup.config.ts
Outdated
plugins: [...createNodePlugins(false, false, false), bundleSizeLimit(120)], | ||
plugins: [...createNodePlugins(false, false, false), bundleSizeLimit(150)], |
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.
It's now 149kB because magic-string
is now bundled in the CJS build.
if (type === 'js' && (!map || map.mappings !== '')) { | ||
const urlWithoutTimestamp = removeTimestampQuery(req.url!) | ||
const ms = new MagicString(content.toString()) | ||
content = getCodeWithSourcemap( | ||
type, | ||
content.toString(), | ||
ms.generateMap({ source: urlWithoutTimestamp, hires: 'boundary' }), | ||
) | ||
} |
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.
This part is the main part of the change. Other changes are to pass { mappings: '' }
as-is to this part.
@@ -31,7 +31,7 @@ const debugCache = createDebugger('vite:cache') | |||
|
|||
export interface TransformResult { | |||
code: string | |||
map: SourceMap | null | |||
map: SourceMap | { mappings: '' } | null |
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.
This change is a breaking change.
But this type was not correctly declared and actually transformRequest
could return { mappings: '' }
if a load
hook returned a map with that and no transform hook transformed that request.
// { mappings: '' } | ||
if ((m as SourceMap).mappings === '') { | ||
combinedMap = { mappings: '' } | ||
break | ||
} | ||
// empty, nullified source map | ||
combinedMap = this.combinedMap = null | ||
this.sourcemapChain.length = 0 | ||
combinedMap = null | ||
break |
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.
This part was not correct. { mappings: '' }
is different from null
. So it shouldn't be changed to null
.
For example, if this.sourcemapChain
is [{ mappings: '' }, validSourcemap]
, the combined result should be { mappings: '' }
instead of validSourcemap
.
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
nuxt, unocss, vite-plugin-react-pages are failing on main too. |
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 think it is a good idea to merge this one soon so other folks will test it during the Vite 5 beta. @bluwy go for it if you are good with these changes.
Just reviewed this. LGTM 👍 Feel free to merge this once the conflicts are resolved @sapphi-red. Looks like it's caused by #14061, so the bundle limit numbers might change. |
Description
I once struggled making this work without adding a big overhead caused by generating sourcemaps (#9476).
This time I came up with a solution using
//# sourceURL
.I tested this with #13503 on Chrome and Firefox (Windows) and it worked for me.
This doesn't work with VSCode's debugger. 😢
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).