Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

domEventHandlers should delay events if they occur while a transaction is running #1507

Closed
Yogu opened this issue Jan 16, 2025 · 2 comments
Closed

Comments

@Yogu
Copy link

Yogu commented Jan 16, 2025

Describe the issue

There is at least one instance where codemirror triggers DOM events from within a transaction: https://github.com/codemirror/view/blob/b20446de33b34e1d4533931893b5737e1ee14eb2/src/docview.ts#L301 (calling blur() causes the blur event to be emitted synchronously). If you listen on this event and dispatch a transaction in the handler, you get the error "Calls to EditorView.update are not allowed while an update is in progress". This is surprising because you don't expect an update to be in progress when you listen on DOM events like "blur".

Can domEventHandlers check if the event occurs within a transaction, and if yes, wait until the transaction is done before it fires?

This "dispatch transaction now if possible, or after the current transaction is processing" logic could also be exposed standalone, I saw this discussion where it was suggested.

Sorry for no reproduction link - I'm not quite sure in which case the blur event is triggered, I only found these cases in our error reporting tool (and am not sure how to reproduce it).

Browser and platform

Chrome on Windows

Reproduction link

No response

@marijnh
Copy link
Member

marijnh commented Jan 17, 2025

I'm not super comfortable introducing magic asynchronicity in a feature that should just be a thin wrapper around DOM events, but yeah, there can be spurious blur/focus events that are synchronously fired during selection update (because moving the DOM selection cannot be done without affecting focus), and I can see how they will cause problems. If you can use focus change effects instead of event handlers, that might be cleaner, but that will not work for all situations.

@Yogu
Copy link
Author

Yogu commented Feb 7, 2025

Thank you, and sorry for the late reply. I think focus change effects work nicely in our case, thanks for the suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants