-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
If insertText does nothing, text is inserted into the DOM anyway, causing DOM/Slate desync (bug introduced in slate-react 0.66.0) #5152
Comments
The diff is pretty small: [email protected]@0.75.0 |
|
Temporary workaround: instead of doing nothing, make an invisible change. Example: https://codesandbox.io/s/workaround-for-slatejs-bug-inserttext-should-do-nothing-if-it-returns-wzc647?file=/index.js |
|
Okay, it gets weirder ... on Chrome, this breaks between [email protected] and [email protected]. But on Firefox, it breaks between [email protected] and [email protected]! Which again suggests that maybe #4889 is not the source of this bug. |
The diff is much larger for the Firefox breakage: [email protected]@0.66.0. Although, like the diff that breaks Chrome, it makes changes to |
The issue is the
Since slate doesn't Definitely a bug, we should always re-render the affected text node in this case. |
Aha, thanks @BitPhinix! So #4889 is nothing to do with this; the cause was #4883. With [email protected], my modern Chrome was being identified as "legacy", in which case Slate does So I suppose the bug has been around for longer. |
To confirm this, I downloaded Chrome 99, as it is not affected by the Chrome regex thing, which was masking the real bug. This time, Chrome v99 agrees with Firefox: the bug was introduced in slate-react 0.66.0. With slate-react 0.66.0, we see the buggy behavior, but with slate-react 0.65.3, it's fine. |
slate-react 0.66.0 introduced this "native event" thing in #3888. So the bug has existed ever since this was first added. |
Any update? |
Any progress on this? |
Description
It is valid for
insertText
to return without doing anything. The expected behavior is that the document is left unchanged. For example, you might want to disallow typing uppercase characters -- you can do this by implementinginsertText
, and if the text is uppercase, do nothing. With slate-react 0.74.2 and below, this works correctly. But with slate-react 0.75.0 and above, it is broken: the text is inserted into the DOM anyway. However, it is (correctly!) NOT inserted into Slate's document -- this means the DOM and the Slate document are then out of sync, leading to further bugs.Sandbox
Example: https://codesandbox.io/s/inserttext-should-do-nothing-if-it-returns-wzc647?file=/index.js
Steps
To reproduce the behavior:
Expectation
If my
insertText
does nothing, nothing should happen.Environment
The text was updated successfully, but these errors were encountered: