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

bugfix: On Preact, sometimes DOM & Slate selection are mismatching #4749

Merged
merged 1 commit into from
Jan 19, 2022

Conversation

Jabher
Copy link
Contributor

@Jabher Jabher commented Dec 27, 2021

Description
Sadly, I cannot create stand-alone reproduction environment, only happens in real world for me.

When switching between multiple editors quickly, there is around 5% chance of following error (location differs):

Uncaught (in promise) Error: Cannot resolve a DOM point from Slate point: {"path":[1,0],"offset":6}

which is caused by this line:
https://github.com/ianstormtaylor/slate/blob/main/packages/slate-react/src/components/editable.tsx#L217

No idea why this only happens on real-world, but I was not able to reproduce this behavior on some demo stage.
However, the environment is the following:

  • Slate 0.72.3, Slate-React 0.72.1
  • Plate 7.x
  • Preact 10.5.4
  • 2 or more editors are present on a same page

Due to fact it is not happening every time, looks like this is race-condition problem and incompatibility between slate and (possibly) preact. However, this logic fully fixes everything.

Checks

  • The new code matches the existing patterns and styles.
  • The tests pass with yarn test.
  • The linter passes with yarn lint. (Fix errors with yarn fix.)
  • The relevant examples still work. (Run examples with yarn start.)
  • You've added a changeset if changing functionality. (Add one with yarn changeset add.)

@changeset-bot
Copy link

changeset-bot bot commented Dec 27, 2021

🦋 Changeset detected

Latest commit: 0fedd28

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 Patch

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

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.

Seems like a reasonable check that won't slow things down or cause harm. Let me know when it's ready for a real review and remember to add a changeset when you're ready.

@Jabher
Copy link
Contributor Author

Jabher commented Dec 29, 2021

Sure! just wanted to check every thing possible

@Jabher Jabher marked this pull request as ready for review January 19, 2022 09:34
@Jabher
Copy link
Contributor Author

Jabher commented Jan 19, 2022

@dylans Hi! Everything is ready, tests are fine... sadly I was not able to figure out how to make stable test that reproduces this behavior. However, all the tests are running fine

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.

Thanks @Jabher . I'm thinking this may also help fix #4789 and other similar issues.

@dylans dylans merged commit a3dfb15 into ianstormtaylor:main Jan 19, 2022
@github-actions github-actions bot mentioned this pull request Jan 19, 2022
@Jabher
Copy link
Contributor Author

Jabher commented Jan 19, 2022

was happy to help!

@BitPhinix
Copy link
Contributor

Sadly this change causes issues for us, checking if the selection is set and in the editor at this stage results in slate-react not updating the selection if it isn't already inside the editor. So focusing and selecting something without having a dom selection (or selection inside the editor) doesn't update/set the dom selection.

BitPhinix added a commit to sliteteam/slate-1 that referenced this pull request Jan 31, 2022
…Selection can mismatch which causes React to break (ianstormtaylor#4749)"

This reverts commit a3dfb15.
@BitPhinix
Copy link
Contributor

BitPhinix commented Jan 31, 2022

@dylans could you revert it? There has to be another way to solve this issue, as this pr breaks basic slate functionality.

dylans added a commit that referenced this pull request Jan 31, 2022
@dylans dylans mentioned this pull request Jan 31, 2022
dylans added a commit that referenced this pull request Jan 31, 2022
* Revert #4749

See note at #4749 (comment)

* Create olive-bags-talk.md

Add changeset
@dylans
Copy link
Collaborator

dylans commented Jan 31, 2022

@dylans could you revert it? There has to be another way to solve this issue, as this pr breaks basic slate functionality.

Done, will release as soon as the CI finishes.

@BitPhinix
Copy link
Contributor

Awesome, thanks so much 👍

@github-actions github-actions bot mentioned this pull request Jan 31, 2022
DougReeder pushed a commit to DougReeder/slate that referenced this pull request Apr 3, 2022
DougReeder pushed a commit to DougReeder/slate that referenced this pull request Apr 3, 2022
* Revert ianstormtaylor#4749

See note at ianstormtaylor#4749 (comment)

* Create olive-bags-talk.md

Add changeset
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.

3 participants