Y-codemirror.next broken if mismatched CodeMirror Package Versions

This isn’t strictly a bug within y-codemirror.next or anything that can necessarily be patched, but I wanted to note this for anyone else that may run into the same problem.

If you are using y-codemirror.next and have multiple versions of @codemirror/view that may be resolved via the dependencies or peerDependencies, CodeMirror instances using the y-codemirror.next extension may stop updating from Y.js docs and reporting changes back to Y.js.

This means the CodeMirror state value may appear empty, and even if it does manage to get the Y.js value, changes in the CodeMirror state will not go back to Y.js.

In my specific case, I have a separate workspace package that contains CodeMirror & does all the setup work, and then integrates that with Y.js in another package, so the dependencies were all out of whack.

I seemingly managed to isolate the problem down to just @codemirror/view’s version being off (note the bold)

The solution in my case was to add the exact CodeMirror package versions to the package.json’s resolutions to ensure they are locked in to the same version.

Package.json:

  "resolutions": {
    "@codemirror/autocomplete": "^6.3.0",
    "@codemirror/commands": "^6.1.1",
    "@codemirror/lang-css": "^6.0.1",
    "@codemirror/lang-html": "^6.4.1",
    "@codemirror/language": "^6.2.1",
    "@codemirror/language-data": "^6.1.0",
    "@codemirror/lint": "^6.0.0",
    "@codemirror/search": "^6.2.1",
    "@codemirror/state": "^6.2.0",
    "@codemirror/theme-one-dark": "^6.1.0",
    "@codemirror/view": "^6.7.3"
  },

After that, the versions matched up and y-codemirror.next began working again.