-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Native browser spellcheck causes errors after replacement in Firefox and Safari #2171
Comments
Any updates? |
Same issue here with latest draft js (0.11.4). |
It seems that something went wrong with this editor (in the latest Chrome, Firefox and Safari on the https://draftjs.org/ site):
|
Yeah, issue is here #2280 |
#2280 is fixed. |
Re-open this bug please. Because editor works incorrectly after spellcheck replacement (steps 1-7). |
Thank you @mrkev. |
Just repro-d using the steps provided. I don't see the exceptions, those might've been fixed. Essentially everything from step 8+ works for me. The text still autocorrects to |
This also occurs in Electron apps (albeit tested using Draft-js v0.10.5, but I suspect a version change will not fix this), where if using webContents' I.e. similar behaviour to this issue, and to this issue, but with Electron. |
So I looked into this and I've characterized the issue a bit more. I don't know the code though, so I'm throwing this in here in case anyone who knows better can solve it before I can. So when I use draftjs.org as my experiment area, I can produce the issue as follows. Lets say I want to write Galley but misspell it galsey. I then format it as Ga ls e y. <div data-offset-key="b6bad-0-0" class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr">
<span data-offset-key="b6bad-0-1" style="font-weight: bold;">
<span data-text="true">Ga</span>
</span>
<span data-offset-key="b6bad-0-2">
<span data-text="true">ls</span>
</span>
<span data-offset-key="b6bad-0-3" style="text-decoration: italic;">
<span data-text="true">e</span>
</span>
<span data-offset-key="b6bad-0-4">
<span data-text="true">y</span>
</span>
</div> After when I finally have spell check applied, I will get Galleyy with the following html. <div data-offset-key="b6bad-0-0" class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr">
<span data-offset-key="b6bad-0-0" style="font-weight: bold;">
<span data-text="true">Galley</span>
</span>
<span data-offset-key="b6bad-0-4">
<span data-text="true">y</span>
</span>
</div> I've observed a few things:
I believe logically that when the spell check is applied that it will collect all the span contents together into the first tag and remove the rest of the tags following. So I expect the bug is with the concatenation of the word removing the following tags and not removing the full length of them (e.g. remove the |
Ah, I think I know exactly why this happens, and it's related to other bugs. First two things to know for background:
In a nutshell, the issue is this:
Therefore, if the text that is supposed to be replaced spans more than one leaf, only part of it gets replaced. There's two ways to go about fixing this: a patch that tries to hack its way around this limitation, or a change in React fixing facebook/react#11211 and then an alternative implementation of |
Are there any updates on this issue? |
This is very closely related (possibly the same) as what I am experiencing. In my case, when using the native autocomplete in Chrome and Safari, it does a re-render with the "insert-characters" changeType first, which gives a concatenation of the partially completed word and the completed word (for example, I type "f" and then autocomplete with the word "for" and the "insert-characters" change will show "ffor"). Next, DraftJS handles this with another update with the changeType of "apply-entity" and the partial word being removed ("ffor" then becomes "for"). If the text has a CompositeDecorator involved then the second "correction" update is not taking place. My guess is that there is a missing test case in editOnInput.js. |
I guess the biggest update is that unfortunately I've left Facebook, so I don't know the status of this anymore /: |
Do you want to request a feature or report a bug?
Bug.
What is the current behavior?
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. You can use this jsfiddle to get started: https://jsfiddle.net/gmertk/e61z7nfa/.
console
.Hello maan.
m
inmaan
word.maan
) and select a replacementmoan
.Hello moanaan.
. The text is incorrect. It should beHello moan.
.Ctrl/Command + A
(Select All).Error: invariant(...): Second argument must be a string.
.a
letter. Other errors will appear in the console:Error: Got unexpected null or undefined
.Enter
key. It will not work.What is the expected behavior?
The misspelled word should be replaced with a correct one. The editor should work properly without any errors and inconsistent behaviour.
Which versions of Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of Draft.js?
Current version in latest Firefox (version 68.0.2) on macOS Mojave (10.14.5). The same problems present in latest Safari (version 12.1.1 ) (but add
Hello maaan
text to the editor).The text was updated successfully, but these errors were encountered: