Timeouts and synchronising external/DOM state?

Hey there, I was wondering if Prosemirror uses internally an event queue or timeouts or equivalent stuff to perform its tasks.

The reason I care is that I want to change the surrounding DOM whenever I create a PM EditorView, by scrolling the DOM Node fully into the document. I have seen that it mostly works if use a setTimeout but sometimes it doesn’t, and I want to avoid “voodoo” timeouts.

So my question is whether PM uses timeouts internally to wait for things, especially during initialisation but also during transactions and state updates. And if yes, if there’s an API I could use to get a callback when an EditorView is fully initialised and attached to the DOM element.

Thanks!

ProseMirror updates (and initializes) synchronously. It does in some cases wait a moment before responding to DOM mutations in order to allow events related to the same change (which the browser models as a sequence of mutations and events) to accumulate, and has a few timeouts internally for other hacks, but that doesn’t sound like it would be the issue here.

1 Like

Thanks for clarifying. I’m also using React and that of course has its own event loop so I will look there. Good to know the various invariants. I guess the timeouts and hacks relate to user input relating to contenteditable, if I stick to responding to various PM events I should be back in synchronous land?

Yes, the API should protect you from these almost entirely (except possibly when you’re doing your own thing in response to DOM events without preventDefault-ing them).

1 Like