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

Crash on text update from outside of the editor when cursor to the right #4094

Open
Obiwarn opened this issue Feb 23, 2021 · 4 comments · May be fixed by #5407
Open

Crash on text update from outside of the editor when cursor to the right #4094

Obiwarn opened this issue Feb 23, 2021 · 4 comments · May be fixed by #5407
Labels

Comments

@Obiwarn
Copy link

Obiwarn commented Feb 23, 2021

When the editor content is updated from outside (e.g. by a database call) then the editor crashes

  • if the new text is shorter than the old text
  • and the cursor has been placed to the right (i.e. is outside of the new shorter text).

I just added a useEffect to the plain text example to show. Just start writing sth. behind the default text in the editor and it will crash.

See:
https://codesandbox.io/s/slate-reproductions-forked-qets6

added code:
useEffect(() => { setInterval(() => setValue(initialValue), 2000); }, []); ;

Any idea how I can prevent / workaround this?

@Obiwarn Obiwarn added the bug label Feb 23, 2021
@eshavrov
Copy link

eshavrov commented Mar 9, 2021

Try resetting the cursor position beforehand. Transforms.deselect(editor);

@Obiwarn
Copy link
Author

Obiwarn commented Mar 9, 2021

Thank you.

I found ReactEditor.blur(editor); which probably does the same.

However, Slate should not crash on this, right?

@eshavrov
Copy link

eshavrov commented Mar 9, 2021

Slate falls because the previous position does not match the new value. You can experimentally decide for yourself what is more convenient for you to use to solve this problem.

@eshavrov
Copy link

eshavrov commented Mar 9, 2021

In my project, in those places where it is critical, I calculate the new position of the cursor. But it's easier of course to just reset this value.

@zbeyens zbeyens linked a pull request Apr 27, 2023 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants