From 7953d131aeac5f8d2420cc8b64e2561b19d71efc Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Sat, 17 Dec 2022 16:55:41 -0700 Subject: [PATCH] Fix monaco editor issues (#4724) * Add sub filter for monaco editor * Don't include files for unused languages * Move necessary files and cleanup build * Update sub filter for new location * Still need to include default editor worker * Fix error when model already exists --- Dockerfile | 4 +++- docker/rootfs/usr/local/nginx/conf/nginx.conf | 1 + web/src/routes/Config.jsx | 9 ++++++++- web/vite.config.ts | 3 ++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index f0eea212a..4dd223df8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -269,7 +269,9 @@ COPY web/package.json web/package-lock.json ./ RUN npm install COPY web/ ./ -RUN npm run build +RUN npm run build \ + && mv dist/BASE_PATH/monacoeditorwork/* dist/assets/ \ + && rm -rf dist/BASE_PATH # Collect final files in a single layer FROM scratch AS rootfs diff --git a/docker/rootfs/usr/local/nginx/conf/nginx.conf b/docker/rootfs/usr/local/nginx/conf/nginx.conf index b59aecb98..eff884c14 100644 --- a/docker/rootfs/usr/local/nginx/conf/nginx.conf +++ b/docker/rootfs/usr/local/nginx/conf/nginx.conf @@ -243,6 +243,7 @@ http { sub_filter '"/BASE_PATH/dist/' '"$http_x_ingress_path/dist/'; sub_filter '"/BASE_PATH/js/' '"$http_x_ingress_path/js/'; sub_filter '"/BASE_PATH/assets/' '"$http_x_ingress_path/assets/'; + sub_filter '"/BASE_PATH/monacoeditorwork/' '"$http_x_ingress_path/assets/'; sub_filter 'return"/BASE_PATH/"' 'return window.baseUrl'; sub_filter '' ''; sub_filter_types text/css application/javascript; diff --git a/web/src/routes/Config.jsx b/web/src/routes/Config.jsx index 66c3d6117..678619301 100644 --- a/web/src/routes/Config.jsx +++ b/web/src/routes/Config.jsx @@ -50,6 +50,13 @@ export default function Config() { const modelUri = Uri.parse('a://b/api/config/schema.json'); + let yamlModel; + if (editor.getModels().length > 0) { + yamlModel = editor.getModel(modelUri) + } else { + yamlModel = editor.createModel(config, 'yaml', modelUri) + } + setDiagnosticsOptions({ enableSchemaRequest: true, hover: true, @@ -66,7 +73,7 @@ export default function Config() { window.editor = editor.create(document.getElementById('container'), { language: 'yaml', - model: editor.createModel(config, 'yaml', modelUri), + model: yamlModel, scrollBeyondLastLine: false, theme: 'vs-dark', }); diff --git a/web/vite.config.ts b/web/vite.config.ts index 27d24ee8e..f3dc20cea 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -10,7 +10,8 @@ export default defineConfig({ 'import.meta.vitest': 'undefined', }, plugins: [preact(), monacoEditorPlugin.default({ - customWorkers: [{label: 'yaml', entry: 'monaco-yaml/yaml.worker'}] + customWorkers: [{ label: 'yaml', entry: 'monaco-yaml/yaml.worker' }], + languageWorkers: ['editorWorkerService'], // we don't use any of the default languages })], test: { environment: 'jsdom',