DevTools: syntax highlighting of Vue files broken when using template strings
Categories
(DevTools :: Debugger, defect, P3)
Tracking
(relnote-firefox 163+, firefox163 fixed)
People
(Reporter: FeBe95, Assigned: FeBe95, Mentored)
Details
Attachments
(3 files, 3 external files)
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0
Steps to reproduce:
- Create a development build of a Vue.js project
- Navigate to http://localhost
- Open DevTools Debugger
- Open the component.vue file
Actual results:
Syntax highlighting breaks when using template strings.
Expected results:
Syntax highlighting should not break.
Comment 1•2 years ago
|
||
The Bugbug bot thinks this bug should belong to the 'DevTools::Debugger' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Comment 2•2 years ago
|
||
Our codemirror lib doesn't have any vue.js mode installed at the moment but it seems supported by codemirror 5 so we should be able to add the necessary mode: https://codemirror.net/5/mode/vue/index.html
We probably have to instruct codemirror to use this mode but it should be straightforward.
Can be a mentored bug.
| Assignee | ||
Comment 3•12 days ago
|
||
I can still reproduce this on a current local build of mozilla-central, where the debugger now uses CodeMirror 6. The highlighting looks a bit different than in the original screenshot, but it's still broken (see attached screenshot).
I'm working on a fix. Since the debugger moved to CodeMirror 6 (bug 1942702), the CodeMirror 5 Vue mode suggested in comment 2 no longer applies. As far as I can tell, .vue sources are currently highlighted as plain JavaScript (vue is in javascriptLikeExtensions in devtools/client/debugger/src/utils/source.js), so the HTML in <template> breaks the JS parser, e.g. when a backtick starts a template literal that never closes.
My plan is to add @codemirror/lang-vue to the CodeMirror 6 bundle and use it for .vue sources in the debugger editor.
| Assignee | ||
Comment 4•12 days ago
|
||
I have a working fix with tests ready (adding @codemirror/lang-vue to the CM6 bundle and using it for Vue single-file components in the debugger editor).
Could you assign this bug to me so I can submit the patches for review?
Updated•12 days ago
|
| Assignee | ||
Comment 6•12 days ago
|
||
Add the CodeMirror 6 Vue language package to the bundle, so that the
debugger editor can highlight Vue single-file components.
The package builds on @codemirror/lang-html and
@codemirror/lang-javascript, which are already bundled, so the minified
bundle only grows by about 3.3 KB.
Note that @codemirror/lang-vue is still at version 0.1.x.
| Assignee | ||
Comment 7•12 days ago
|
||
All sources except stylesheets were highlighted with the JavaScript
mode. In Vue single-file components, this breaks the highlighting, e.g.
as soon as a template literal is used.
The editor mode is now picked for each source by getEditorMode(),
which returns an Editor.modes value (as suggested in D258553): CSS for
stylesheets, Vue for Vue single-file components, and JavaScript
otherwise. The mode is now set for every source, as the editor instance
is shared between sources. Previously, the CSS mode set for a
stylesheet was kept for all sources selected afterwards.
Vue single-file components are detected like in parseVueScript in the
parser worker: the content type is "text/vue" and the content starts
with <. The content check is needed because bundlers also generate
JavaScript modules for .vue files: webpack vue-loader's virtual modules
(e.g. App.vue?12ab) are original sources with the "text/vue" content
type, while Vite's generated App.vue / App.vue?t=… modules have a
JavaScript content type.
Known limitation: blocks using another language, like
<script lang="ts"> or <style lang="sass">, are not highlighted with
that language yet (bug <bug>).
Tested manually with webpack and Vite projects.
| Assignee | ||
Comment 8•12 days ago
|
||
Add a test task to browser_dbg-editor-mode.js covering:
- a Vue single-file component, which uses the Vue mode,
- a webpack vue-loader style virtual module (
Virtual.vue?12ab), which
uses the JavaScript mode, - switching from a Vue source back to a JavaScript source.
The single-file component fixture is based on the parser worker's
vue-sample.vue fixture, with an additional template literal.
Comment 10•6 days ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/e3a64f9e7db8
https://hg.mozilla.org/mozilla-central/rev/a1502fcf85de
https://hg.mozilla.org/mozilla-central/rev/3d92382d8152
| Assignee | ||
Comment 11•6 days ago
|
||
For reference, this is how it looks in Nightly right now, with the fix in place.
Comment 12•6 days ago
|
||
Did you want to nominate this for the Fx163 relnotes? If so, set the relnote-firefox flag to "?"
https://wiki.mozilla.org/Release_Management/Release_Notes_Nomination
Possible wording:
The Debugger now highlights Vue single-file components as Vue instead of JavaScript, so their syntax highlighting no longer breaks on template literals.
| Assignee | ||
Comment 13•5 days ago
|
||
Release Note Request (optional, but appreciated)
[Why is this notable]: Vue single-file components (.vue files) were highlighted as plain JavaScript in the Debugger, which broke their syntax highlighting. Vue is a widely used framework, so this improves debugging for many web developers.
[Affects Firefox for Android]: No
[Suggested wording]: The Debugger now supports syntax highlighting for Vue single-file components (.vue files).
[Links (documentation, blog post, etc)]:
Description
•