coordsAtPos and posAtCoords not compatible (RangeError)

I’m trying to find out which position is currently visible in the middle of the screen.

Wanted to use EditorView.posAtCoords to achieve this. However, I constantly get

RangeError: Trying to find position for a DOM position outside of the document

So I tried to find out what valid coords looke like by using EditorView.coordsAtPos:

let coords = view.coordsAtPos(1249) // 1249 is a valid position inside the current view port

// coords includes a valid set of coordinates and does not throw an error

let pos = view.posAtCoords({
    x: coords.left,

Even this throws the error above. How is this possible? Am I missing something?

I don’t know what might be going on there—when I try this, it works. Could it be that you have some overlay over your editor, or a CSS transformation, which is causing the browser to not actually associate the editor’s DOM with those coordinates?

Well, you might be right. There’s a lot of overlaying stuff going on in my use-case.

I switched to using EditorView.blockAtHeight instead and this produces the desired results.