Repository navigation
feat: add JavaScript and CSS support to script and style blocks in HT… - #5994
Merged
knolleary merged 4 commits intoOct 14, 2026
Merged
Conversation
This was referenced Oct 11, 2026
Merged
Contributor
Author
|
demo of what this brings. to be clear, without this, the content of template-node-script-style-demo.mp4 |
2 of 6 tasks
…ML editors
The template node and any other HTML editor only highlight code in <script> and
<style> blocks. This adds completion, hover, signature help, go to definition and
error checking for that code, using Monaco's own TypeScript and CSS workers on a
hidden copy of each block, the same approach VS Code's HTML support uses.
- New monaco-embedded.js, registered for html and handlebars out of the box
- {{...}} is treated as a placeholder, so mustache templates don't show false errors
- CSS checking works today; CSS completion, hover and colours switch on when
Monaco provides monaco.css.getWorker() (nr-monaco-build)
- Public API so other HTML-like languages can opt in and adjust the JavaScript,
e.g. type `this` for their own runtime: RED.editor.codeEditor.monaco
.registerEmbeddedLanguages() and .registerHTMLLanguage()
- getWorkerUrl now wraps the function the Monaco bundle already defines (Node-RED's
own was never used) and points HTML-like languages at the html worker
A registerEmbeddedLanguages() wrap() hook can wrap a script in a helper call, e.g.
Dashboard's __uiTemplate({ ... }). With the cursor inside its arguments, parameter
hints showed the helper and its full internal type. Completion and hover already
left out names matching hiddenNames; parameter hints now do too.
New files no longer need it.
Steve-Mcl
force-pushed
the
feat/monaco-embedded-languages
branch
from
October 13, 2026 10:07
555858e to
138f74a
Compare
2 of 6 tasks
Steve-Mcl
added a commit
to FlowFuse/node-red-dashboard
that referenced
this pull request
Oct 14, 2026
Builds on node-red/node-red#5994, which adds JavaScript and CSS support to <script> and <style> blocks in Node-RED's HTML editors and lets other HTML-like languages opt in. This opts the ui-template's vue-sfc language in and adds what is specific to Dashboard: the type of `this`. - Component scripts (a single `export default { ... }`) are wrapped in the hidden copy so `this` in data, computed, methods, watch, mounted and unmounted knows the component's members and what Dashboard adds (send, submit, msg, value, id, props, $socket, $store, $router, $vuetify, ...) - Other scripts, which Dashboard runs inside mounted, get the same `this` - Only loaded when Node-RED provides registerEmbeddedLanguages, so older Node-RED is unaffected - The plugin uses Node-RED's registerHTMLLanguage when present, which also maps the worker, instead of its own registration and worker shim
Steve-Mcl
added a commit
to FlowFuse/node-red-dashboard
that referenced
this pull request
Oct 15, 2026
Builds on node-red/node-red#5994, which adds JavaScript and CSS support to <script> and <style> blocks in Node-RED's HTML editors and lets other HTML-like languages opt in. This opts the ui-template's vue-sfc language in and adds what is specific to Dashboard: the type of `this`. - Component scripts (a single `export default { ... }`) are wrapped in the hidden copy so `this` in data, computed, methods, watch, mounted and unmounted knows the component's members and what Dashboard adds (send, submit, msg, value, id, props, $socket, $store, $router, $vuetify, ...) - Other scripts, which Dashboard runs inside mounted, get the same `this` - Only loaded when Node-RED provides registerEmbeddedLanguages, so older Node-RED is unaffected - The plugin uses Node-RED's registerHTMLLanguage when present, which also maps the worker, instead of its own registration and worker shim
Steve-Mcl
added a commit
to FlowFuse/node-red-dashboard
that referenced
this pull request
Oct 16, 2026
Builds on node-red/node-red#5994, which adds JavaScript and CSS support to <script> and <style> blocks in Node-RED's HTML editors and lets other HTML-like languages opt in. This opts the ui-template's vue-sfc language in and adds what is specific to Dashboard: the type of `this`. - Component scripts (a single `export default { ... }`) are wrapped in the hidden copy so `this` in data, computed, methods, watch, mounted and unmounted knows the component's members and what Dashboard adds (send, submit, msg, value, id, props, $socket, $store, $router, $vuetify, ...) - Other scripts, which Dashboard runs inside mounted, get the same `this` - Only loaded when Node-RED provides registerEmbeddedLanguages, so older Node-RED is unaffected - The plugin uses Node-RED's registerHTMLLanguage when present, which also maps the worker, instead of its own registration and worker shim
Steve-Mcl
added a commit
to FlowFuse/node-red-dashboard
that referenced
this pull request
Oct 17, 2026
Builds on node-red/node-red#5994, which adds JavaScript and CSS support to <script> and <style> blocks in Node-RED's HTML editors and lets other HTML-like languages opt in. This opts the ui-template's vue-sfc language in and adds what is specific to Dashboard: the type of `this`. - Component scripts (a single `export default { ... }`) are wrapped in the hidden copy so `this` in data, computed, methods, watch, mounted and unmounted knows the component's members and what Dashboard adds (send, submit, msg, value, id, props, $socket, $store, $router, $vuetify, ...) - Other scripts, which Dashboard runs inside mounted, get the same `this` - Only loaded when Node-RED provides registerEmbeddedLanguages, so older Node-RED is unaffected - The plugin uses Node-RED's registerHTMLLanguage when present, which also maps the worker, instead of its own registration and worker shim
2 of 6 tasks
n-lark
pushed a commit
to FlowFuse/node-red-dashboard
that referenced
this pull request
Oct 21, 2026
Builds on node-red/node-red#5994, which adds JavaScript and CSS support to <script> and <style> blocks in Node-RED's HTML editors and lets other HTML-like languages opt in. This opts the ui-template's vue-sfc language in and adds what is specific to Dashboard: the type of `this`. - Component scripts (a single `export default { ... }`) are wrapped in the hidden copy so `this` in data, computed, methods, watch, mounted and unmounted knows the component's members and what Dashboard adds (send, submit, msg, value, id, props, $socket, $store, $router, $vuetify, ...) - Other scripts, which Dashboard runs inside mounted, get the same `this` - Only loaded when Node-RED provides registerEmbeddedLanguages, so older Node-RED is unaffected - The plugin uses Node-RED's registerHTMLLanguage when present, which also maps the worker, instead of its own registration and worker shim
1 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Types of changes
The main reason for this work is to work towards supporting vue and vuetify in dashboard-2:
As a happy side effect, this enables embedded
<script>and<style>blocks in all monaco editors in Node-RED set tohtmlmode - providing error checking and code completions for users writing HTML.Note
This is a feature but it builds on monaco 0.57.0 (which is a bug fix PR pointed at
main). If you would prefer this to be based offdev, I will repoint it once monaco 0 57 is merged anddevhas been updated.Proposed changes
Code in
<script>and<style>blocks only gets syntax highlighting in the Monaco editor today. That covers the template node and any other node that edits HTML. This PR adds proper language support for that code:<script>: completion, hover info, parameter hints, go to definition and error checking<style>: completion, hover, colour previews and error checkingIt works out of the box for
htmlandhandlebarseditors. No settings, no extra download, no new workers.How it works
A new
code-editors/monaco-embedded.jskeeps a hidden model for each document holding only the embedded code, with everything else blanked out (newlines kept), so positions line up with the real document. Monaco's existing TypeScript and CSS workers answer for those hidden models, and the results and markers are mapped back onto the editor. This is the same "embedded document" approach VS Code uses for its HTML support. It only uses public Monaco APIs.A few details worth knowing:
{{...}}and{{{...}}}are treated as placeholders inside the blocks, so a mustache template likeconst data = {{{payload.json}}}doesn't show false errors.getAnnotations()reports to nodes.editor:closecleanup.API for other HTML-like languages
Nodes and plugins that register their own HTML-like language can opt in:
RED.editor.codeEditor.monaco.registerEmbeddedLanguages(languageId, options)turns this on for another language. The options can adjust how the JavaScript is read, e.g. wrap it and add type declarations sothisis typed for that node's runtime. I'll use this in FlowFuse Dashboard's ui-template to typethisfor its Vue components (this.send(),this.msg, data/methods...).RED.editor.codeEditor.monaco.registerHTMLLanguage(languageId, options)registers Monaco's HTML language service for another language and makes sure it gets the html worker.Worker fix
While testing I found that Node-RED's
MonacoEnvironment.getWorkerUrlis never used. Monaco loads asynchronously and the bundle already defines its owngetWorkerUrl, sowindow.MonacoEnvironment.getWorkerUrl || function ...always kept the bundle's version. That version returns.../dist/undefinedfor labels it doesn't know, such as a language registered withregisterHTMLLanguageService(). Monaco then falls back to running the worker on the main thread, and its requests never get an answer. Node-RED now wraps whatever function is already there and points HTML-like languages at the html worker.Related
chore/update-monaco-0.57.0), which vendors the nr-monaco-build 0.57.0 release. That release addsmonaco.css.getWorker()andmonaco.html.getWorker()(the same shape as Monaco's ownmonaco.json.getWorker()), which the CSS completion, hover and colour previews here need.Testing
test/unit/@node-red/editor-client/ui/editors/code-editors/monaco-embedded_spec.jsfor finding script/style blocks, building the hidden document, mustache placeholders and offset mapping. 19 editor-client tests pass, andnpm run lintis clean.{{...}};Checklist
npm run testto verify the unit tests pass