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

OnSelect sometimes returns the old value #3348

Closed
sirgru opened this issue Dec 18, 2019 · 2 comments
Closed

OnSelect sometimes returns the old value #3348

sirgru opened this issue Dec 18, 2019 · 2 comments
Labels

Comments

@sirgru
Copy link

sirgru commented Dec 18, 2019

Do you want to request a feature or report a bug?

Report a bug.

What's the current behavior?

I have noticed the onSelect event sometimes runs with the old selection value, sometimes with the new selection.
If you select text multiple times, in combinations of range select and click especially, every once in a while it will report the old value.
This makes certain other kinds of bugs hard to catch for developers, because the behavior is erratic.

https://codesandbox.io/s/slate-reproductions-8n7q5
https://recordit.co/j053446P1S
http://g.recordit.co/j053446P1S.gif

Slate: 0.56.0
Browser: Chrome
OS: Windows

What's the expected behavior?

onSelect should fire consistently, with the value of the new selection made.

@sirgru
Copy link
Author

sirgru commented Dec 18, 2019

Another thing I've noticed: setting any kind of value via hooks in onSelect sometimes returns the cursor to the previous position. This seems related.

@ianstormtaylor
Copy link
Owner

The onSelect handler is a synthetic React polyfill that isn't really triggered when the selection changes (it's trigger on click, on keydown, etc.). Unfortunately the React events started out as proper spec-compliant polyfills, but that was years ago and they haven't kept pace, so these days there are many gaps that aren't properly covered and it doesn't seem like they're going to fix the synthetic events at all. Here's an issue specifically tracking selectionchange: facebook/react#5785

If you're looking to do things when the editor's selection changes you should likely use onChange instead. I'd be open to adding an onDOMSelectionChange if someone wants to PR to get the real DOM event which would actually be accurate.

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

No branches or pull requests

2 participants