@codemirror/view 6.3.0 -> 6.3.1 breaks EditorView.setState

The upgrade of @codemirror/view 6.3.0 to 6.3.1 introduced an error that I have been trying to figure out.

The following sequence of events throws an Uncaught RangeError: Trying to find position for a DOM position outside of the document

const view = new EditorView({
  state: EditorState.create(),
  parent: document.getElementById('editor')
})

Then, you click in the editor somewhere. Then, you call a function that does this:

view.setState(EditorState.create())

This will throw the RangeError. Crucially, if you don’t actually click in the editor, it won’t throw the error, so I’m wondering if it has something to do with selections.

The issue isn’t the empty state, I only am using that here to show that the error occurs even with no extensions at all. I bisected the various releases of codemirror to figure out where the bug started happening, so hopefully this is helpful. For now, I’ve downgraded to 6.3.0.

Anyone else seen this issue?

I can’t reproduce this. Can you create a codemirror.net/try example that shows it? (That page is running the latest library versions.)

I’m not able to reproduce this in the Try CodeMirror, although I’m having to use setTimeout instead of triggering an action from a button like I’m doing in my application.

I’ll see if I can figure out exactly which commit broke it or otherwise provide more detail to help chase this down.

It was this specific commit that breaks the editor. Any theories for what might be going on?

I remember that introduced some kind of regression that was later fixed. Did you confirm that the same problem exists with the current code?

Confirmed. The same problem is on the latest version, 6.7.3.

(As an aside, our company contributes a modest monthly fee to your cause via GitHub subscriptions. I read somewhere that you asked folks to mention that when commenting here!)

I’m happy to debug this if you can provide a self-contained script that demonstrates the issue.