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

Use native character insertion to fix browser/OS text features #3888

Merged
merged 11 commits into from Aug 11, 2021
Merged

Use native character insertion to fix browser/OS text features #3888

merged 11 commits into from Aug 11, 2021

Conversation

bkrausz
Copy link
Contributor

@bkrausz bkrausz commented Sep 25, 2020

See #3293, which hasn't seen any action despite a change request. This takes that PR and makes TextString a functional component, the one requested change.

Huge thanks to @luddep for doing almost all of the work here.

Does this fix any issues or need any specific reviewers?

Fixes: #2061 (and some of #2051?)
Reviewers: @ianstormtaylor

@bkrausz bkrausz changed the title Lp native single character inserts Use native character insertion to fix browser/OS text features Sep 25, 2020
@maccman
Copy link

maccman commented Nov 25, 2020

This spell-checking bug essentially makes Slate unusable in production in my opinion.

I know Slate has some new core-contributors - I urge them to look at this PR.

@maccman
Copy link

maccman commented Dec 2, 2020

Here's my hacky workaround I'm using for now:

  const debouncedSetSpellCheck = useMemo(() => debounce(setSpellCheck, 300), [])

  const toggleSpellCheck = () => {
    // Slate has a spell checking bug where spell checking gets invoked too
    // aggressively. We can work around this by toggling it when the user types.
    // https://rb.gy/qycfpa
    setSpellCheck(false)
    debouncedSetSpellCheck(true)
  }

And:

          onChange={newValue => {
              toggleSpellCheck()
            }
          }}>

          <EditablePlugins
            spellCheck={spellCheck}```

Copy link
Owner

@ianstormtaylor ianstormtaylor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me generally. It just needs someone to verify that this doesn't break other things, since this is a pretty core change.

@bkrausz
Copy link
Contributor Author

bkrausz commented Dec 7, 2020

I've been using this in production on a fork for months now with no major issues, though all of our users are on Chrome.

The only issue I found was in doing complex normalizations on top of nativeOps, I just fixed that via the latest commit (only required an extra withoutNormalization.

Is there other verification you would like to see?

@luddep
Copy link
Contributor

luddep commented Dec 12, 2020

If you want to cherry-pick d7e444a, it solves a macOS chrome bug where a long press to select a special character (hold a + press 4 = ä) would double insert until native events flushed -- solved for now by just sidestepping it entirely and limiting native events to single char a-z inserts. In my limited testing, those are the only keyboard events (on US keyboards) that trigger spell check corrections.

@MohsenElgendy
Copy link

Is there an estimation on when would this PR be merged with the master?

@cmditch
Copy link
Contributor

cmditch commented Jul 30, 2021

Very glad a fix for the spellcheck flicker is out there. Appreciate the work @ryanmitts, @luddep, @bkrausz have put towards this. 🎉

Pretty excited for this fix to get merged.

@thesunny do you see any issues with the logic of this PR?

Copy link
Collaborator

@dylans dylans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate to ask @bkrausz given how long this PR (and its previous form have been going), but if you could rebase it against the latest in main, I will get this landed asap. If you don't have time I'll do the rebase.

luddep and others added 3 commits August 5, 2021 17:20
…kering spellcheck, autocorrect, text shortcuts, etc.)

move some checks into previous if statement, remove commented out code

move native behavior into `slate-react`, and remove any external interface

dont use native editing if marks are set, as a new node will be inserted

match -> above

remove nativeOperationsQueue from editor

bail out of native queueing and immediately flush events if non insert_text operation is being applied.
@changeset-bot
Copy link

changeset-bot bot commented Aug 6, 2021

🦋 Changeset detected

Latest commit: ee08862

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
slate-react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@bkrausz
Copy link
Contributor Author

bkrausz commented Aug 6, 2021

@dylans done. I'm having trouble getting tests to pass on my local machine, but the same 5 fail for me on main and on this branch, so hopefully nothing to fix.

@bkrausz bkrausz requested a review from dylans August 6, 2021 00:42
…r or space, to limit potential bad side effects.
@dylans
Copy link
Collaborator

dylans commented Aug 6, 2021

@dylans done. I'm having trouble getting tests to pass on my local machine, but the same 5 fail for me on main and on this branch, so hopefully nothing to fix.

Ok, we do have one integration test that appears to be legitimately failing now @bkrausz , the test in https://github.com/ianstormtaylor/slate/blob/main/cypress/integration/examples/code-highlighting.ts#L19-L34

Here's the specific error: 1) code highlighting highlights javascript syntax: AssertionError: Timed out retrying after 4000ms: expected '<span.css-14qid8c>' to contain 'const' at Context.eval (http://localhost:3000/__cypress/tests?p=cypress/integration/examples/code-highlighting.ts:124:14)

Please have a look when you have time.

@bkrausz
Copy link
Contributor Author

bkrausz commented Aug 6, 2021

Is it possible that this test is flaky? I'm seeing it working correctly locally, both via test passing and manually checking on a new build. Would you mind triggering a re-run to confirm and/or snagging the video from the test server? I don't have access to either.

@bkrausz
Copy link
Contributor Author

bkrausz commented Aug 6, 2021

On further inspection it looks like this PR isn't actually doing what it claims to do anymore...we still get flickering on spellcheck. I'm using it to get other native actions (specifically so horizontal scroll will work so Slate can emulate Input boxes). This PR needs deeper investigation: we are still avoiding calling preventDefault, but it seems that's no longer sufficient.

I doubt I'll have time to go that deep on this PR and fix it again, if anyone else is interested in taking this over that would be more than welcome.

@lukesmurray
Copy link
Contributor

If anyone wants to do it you could potentially use git bisect to find the commit where the change broke.

@bkrausz
Copy link
Contributor Author

bkrausz commented Aug 6, 2021

FYI this PR does in fact still fix autocorrect support in Safari, just not the spellcheck squiggle blink.

@bkrausz
Copy link
Contributor Author

bkrausz commented Aug 6, 2021

Ok, I got nerdsniped enough to bisect this...it's from #4158, which causes every string to rerender. I'm pushing up a revert for it, can someone who knows how to test IME see if the bug described there is also fixed by this one? We may need to add a few extra characters to the allowlist, as I don't know what characters it produces.

@dylans
Copy link
Collaborator

dylans commented Aug 7, 2021

Ok, I got nerdsniped enough to bisect this...it's from #4158, which causes every string to rerender. I'm pushing up a revert for it, can someone who knows how to test IME see if the bug described there is also fixed by this one? We may need to add a few extra characters to the allowlist, as I don't know what characters it produces.

I know how to test IME. I’ll look at it over the weekend.

Copy link
Collaborator

@dylans dylans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good to me @bkrausz... I'm going to let it sit for a couple more days so I can give it another look and in case anyone else wants to take a second look.

Co-authored-by: Dylan Schiemann <[email protected]>
@dylans dylans merged commit 25afbd4 into ianstormtaylor:main Aug 11, 2021
This was referenced Aug 11, 2021
@githoniel
Copy link
Contributor

githoniel commented Aug 13, 2021

@bkrausz sorry for the bug caused by my hacky PR that drove you crazy😥。

@dylans but this pr did not fix the IME double input when add mark bug. I have test in the main branch with this pr merged like below:
xx

this anoy bug will cause slate to crash when click on the text that should not exist.

I have a new idea to fix this without force re-render string component. I will try to implement later

@dylans
Copy link
Collaborator

dylans commented Aug 13, 2021

@bkrausz sorry for the bug caused by my hacky PR that drove you crazy😥。

@dylans but this pr did not fix the IME double input when add mark bug. I have test in the main branch with this pr merged like below:
xx

this anoy bug will cause slate to crash when click on the text that should not exist.

I have a new idea to fix this without force re-render string component. I will try to implement later

ok @githoniel let me know. We've had quite a few IME related contributions lately and it would be great to be done with the double input issue resolved for good.

@dylans
Copy link
Collaborator

dylans commented Aug 18, 2021

@bkrausz fyi, this update seems to have caused a regression for code highlighting/decorations, see the notes in #4445.

@dylans dylans mentioned this pull request Aug 19, 2021
5 tasks
@dylans dylans mentioned this pull request Sep 11, 2021
dylans added a commit to dylans/slate that referenced this pull request Sep 13, 2021
…ormtaylor#3888)

* use native character insertion to fix browser/OS text features. (flickering spellcheck, autocorrect, text shortcuts, etc.)

move some checks into previous if statement, remove commented out code

move native behavior into `slate-react`, and remove any external interface

dont use native editing if marks are set, as a new node will be inserted

match -> above

remove nativeOperationsQueue from editor

bail out of native queueing and immediately flush events if non insert_text operation is being applied.

* Convert TextString to a functional component

* Batch normalization of native op application

* Add changeset

* only proceed as native event if single character non-special character or space, to limit potential bad side effects.

* Revert "fix ime double input with mark"

* Comment wording tweak

Co-authored-by: Dylan Schiemann <[email protected]>

* Comment wording tweak

Co-authored-by: Dylan Schiemann <[email protected]>

* Comment wording tweak

Co-authored-by: Dylan Schiemann <[email protected]>

* Comment wording tweak

Co-authored-by: Dylan Schiemann <[email protected]>

* Comment wording tweak

Co-authored-by: Dylan Schiemann <[email protected]>

Co-authored-by: Ludwig Pettersson <[email protected]>
Co-authored-by: Dylan Schiemann <[email protected]>
@jaked
Copy link
Contributor

jaked commented Oct 15, 2021

rather than defer the insertText call to the underlying Editor, would it make sense to accumulate native operations in onDOMBeforeInput and flush them in onInput entirely within Editable, so insertText is not called at all until onInput? It seems like a lot of the bugs around this (e.g. #4530, #4541) have to do with interactions with non-default insertText implementations.

If this seems like a reasonable idea I can try to do a PR.

@dylans
Copy link
Collaborator

dylans commented Oct 15, 2021

rather than defer the insertText call to the underlying Editor, would it make sense to accumulate native operations in onDOMBeforeInput and flush them in onInput entirely within Editable, so insertText is not called at all until onInput? It seems like a lot of the bugs around this (e.g. #4530, #4541) have to do with interactions with non-default insertText implementations.

If this seems like a reasonable idea I can try to do a PR.

Seems worth a try to me.

@juliankrispel
Copy link
Collaborator

juliankrispel commented Dec 13, 2021

Was this fixed as part of these prs? I have built commits from both this pr and #4605 and have not found a working version. Pointers appreciated 🙏

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

Successfully merging this pull request may close these issues.

fix spellcheck blinking as you type