CodeMirror Empty Changes Array


I’m saving the CodeMirror transactions in my database and I’m having a difficulty understanding certain parts of the transaction. First of all, I’m seeing this transaction:


This seems to result in the following error:

Uncaught RangeError: Applying change set to a document with the wrong length
    at _ChangeSet.apply (chunk-WGZ5GUV2.js?v=ea169c73:817:13)
    at get newDoc (chunk-WGZ5GUV2.js?v=ea169c73:2034:51)
    at _EditorState.applyTransaction (chunk-WGZ5GUV2.js?v=ea169c73:2314:31)
    at get state (chunk-WGZ5GUV2.js?v=ea169c73:2053:23)
    at _EditorView.update (chunk-WOPUBE4N.js?v=ea169c73:6665:18)
    at _EditorView.dispatchTransactions (chunk-WOPUBE4N.js?v=ea169c73:6625:145)
    at _EditorView.dispatch (chunk-WOPUBE4N.js?v=ea169c73:6647:10)
    at collab.jsx?t=1709926792738:272:43

I also checked a transaction which does not result in an error and it looks like this:


The only difference is that the changes array has the value 207 instead of nothing in it.

I have two questions:

  1. Why would an empty changes array lead to a wrong length error.
  2. What does the number in the changes array mean?

Assuming these are the JSON representation of ChangeSet objects, the empty array represents no changes made to a zero-length document, and as such wouldn’t be valid for applying to a non-empty document. The numbers in these arrays encode changed and unchanged pieces of the document, and are not something you want to manipulate or read directly in your code.