yjs / y-codemirror.next

Collaborative extensions for CodeMirror6
Other
159 stars 38 forks source link

Doesn't work as intended without being `mounted` in Vue3/Nuxt. #21

Open bxff opened 2 years ago

bxff commented 2 years ago

Checklist

Describe the bug

When the CodeMirror 6 instance is not mounted in Vue3(Nuxt, in my case), there are problems with synchronisations. When an instance is running with some text and a new instance is created in another browser tab, there is no synchronisation and there are errors in the console. Errors in the console:

Screenshot 2022-10-13 at 11 06 35 PM Screenshot 2022-10-13 at 11 06 56 PM

To Reproduce Steps to reproduce the behavior:

  1. Create a sample Nuxt3 project.
  2. Replace the index.vue with the code bellow, and install libraries as needed:
    
    <template>
    <div class="main" ref="main"></div>
    </template>


**Expected behavior**
`state` should be able to be created without being inside `mounted`. I have never needed to create `state` inside `mounted` before, and there is nothing in the documentation that indicates this should be the case, therefore I believe this is an issue.

**Screenshots**
Given above.

**Environment Information**
 - Chromium / Edge
 - Yjs latest version.
dmonad commented 2 years ago

Usually, the state of CodeMirror plugins is stateless. That's why it doesn't matter, usually, whether you define a plugin state before or after mount. The Yjs plugins, however, are stateful and depend on the view to work. While your component is mounting, the Yjs document might receive some content from a remote peer. The plugin-state changes, but the plugin cannot update the view (force the view to transition to a new state that reflects the value of the Yjs document).

I'm not sure how to fix this at the moment. Since there is an easy solution to it - initialize the state with the view, it's not a high priority right now for me. But I'll leave the ticket open and will come back to it eventually.

vadolasi commented 1 year ago

I have basically the same problem