Closed Bug 1873907 Opened 2 years ago Closed 6 days ago

DevTools: syntax highlighting of Vue files broken when using template strings

Categories

(DevTools :: Debugger, defect, P3)

Firefox 121
defect

Tracking

(relnote-firefox 163+, firefox163 fixed)

RESOLVED FIXED
163 Branch
Tracking Status
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:

  1. Create a development build of a Vue.js project
  2. Navigate to http://localhost
  3. Open DevTools Debugger
  4. Open the component.vue file

Actual results:

Syntax highlighting breaks when using template strings.

Expected results:

Syntax highlighting should not break.

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.

Component: Untriaged → Debugger
Product: Firefox → DevTools

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.

Mentor: hmanilla
Severity: -- → S3
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3
Attached image pasted-image.png —

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.

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?

Flags: needinfo?(hmanilla)
Assignee: nobody → mail
Flags: needinfo?(hmanilla)

Great . Thanks for picking this up, I've assigned this to you.

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.

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.

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.

Pushed by hmanilla@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/2f3af9d61748 https://hg.mozilla.org/integration/autoland/rev/e3a64f9e7db8 [devtools] Add @codemirror/lang-vue to the CodeMirror 6 bundle. r=devtools-reviewers,bomsy https://github.com/mozilla-firefox/firefox/commit/77029ddcac94 https://hg.mozilla.org/integration/autoland/rev/a1502fcf85de [devtools] Use Vue syntax highlighting for Vue single-file components in the debugger. r=devtools-reviewers,bomsy https://github.com/mozilla-firefox/firefox/commit/53c0fca7c5dd https://hg.mozilla.org/integration/autoland/rev/3d92382d8152 [devtools] Test Vue syntax highlighting in the debugger. r=devtools-reviewers,bomsy

For reference, this is how it looks in Nightly right now, with the fix in place.

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.

Flags: needinfo?(mail)

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)]:

relnote-firefox: --- → ?
Flags: needinfo?(mail)

Added to the Fx163 relnotes.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: