Skip to content

Commit

Permalink
Fix monaco editor issues (blakeblackshear#4724)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
NickM-27 committed Dec 17, 2022
1 parent c6f0abf commit 7953d13
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docker/rootfs/usr/local/nginx/conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<body>' '<body><script>window.baseUrl="$http_x_ingress_path/";</script>';
sub_filter_types text/css application/javascript;
Expand Down
9 changes: 8 additions & 1 deletion web/src/routes/Config.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ export default function Config() {

const modelUri = Uri.parse('a:https://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,
Expand All @@ -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',
});
Expand Down
3 changes: 2 additions & 1 deletion web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 7953d13

Please sign in to comment.