Replies: 6 comments
-
i have the same question on vue3.x |
Beta Was this translation helpful? Give feedback.
-
I have solved this problem, here is my solution: Don’t let your editor instance be a reactive variable, but as an ordinary variable change
to
|
Beta Was this translation helpful? Give feedback.
-
you solved my problem, thank you very much |
Beta Was this translation helpful? Give feedback.
-
@Month7 I don't think that works for my use case, since the editor must be converted to a proxy to be shared between Vue blocks (e.g. between setup, mounted, and methods), or to be shared with other Vue components. However, I found a hack that seems to work, // Vue stuff
data(component) {
return {
editor: null as editor.IStandaloneCodeEditor | null,
};
},
mounted() {
const editor = monaco.editor.create(element, {});
this.editor = Object.freeze(editor);
console.log(this.editor.getValue()); // Prints correctly.
}
// More Vue stuff |
Beta Was this translation helpful? Give feedback.
-
Note: I ran into the same issue again, this time with context keys. Also fixed with freeze. this.editor = Object.freeze(monaco.editor.create(element, {}));
this.contextKey = Object.freeze(this.editor.createContextKey('myContextKey', false));
this.contextKey.set(true); |
Beta Was this translation helpful? Give feedback.
-
When I was using Vue 2, Object.freeze was my go-to solution to prevent reactivity issues with the Monaco Editor instance. It worked well and avoided any interference from Vue's reactivity system. But when I migrated to Nuxt/Vue 3, this approach started breaking things. I got errors like: It turns out Vue 3's reactivity system interacts differently with frozen objects, and that messed up Monaco Editor's internal behavior. After some trial and error, I found that using shallowRef solved the problem. Unlike Object.freeze, shallowRef keeps Vue from deeply reacting to the Monaco Editor instance, but still lets you use it as expected. You just have to define the editor variable like this at start : |
Beta Was this translation helpful? Give feedback.
-
monaco-editor version: 0.29.1
Browser: chrome
OS:
Playground code that reproduces the issue:
this step
Beta Was this translation helpful? Give feedback.
All reactions