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

Cannot resolve a DOM point from Slate point #4323

Open
ghingis opened this issue Jun 7, 2021 · 1 comment · May be fixed by #5407
Open

Cannot resolve a DOM point from Slate point #4323

ghingis opened this issue Jun 7, 2021 · 1 comment · May be fixed by #5407
Labels

Comments

@ghingis
Copy link

ghingis commented Jun 7, 2021

I saw a couple of closed ticket with this error, but we think our issue is a bit different from those.
We have a scenario, where Slate is just a part of a document editor.

  const editorRef = useRef<ReactEditor>()
  if (!editorRef.current) {
    editorRef.current = withReact(createEditor())
  }
  const editor = editorRef.current

This document editor has it's own history, so we can not use slate-history.
Whenever this document editor undos or redus, we update the value of Slate and we get the error in the title.

As far as we can tell, the error happens when the position of the cursor will be invalid for the new value.
This is something that should be easy to fix, we just have to save the selector as well in the document state when onChange happens in Slate.

But the onChange does not provide a selector and the editor.selector does not represent the new state of the selector at the time when the onChange fires.

So either way slate should provide a way to get the proper selector for the change.
And also there should be a safe way to set a new selector too, since if we set the selector before the editor gets the new value, it crashes with the same error, but there is no event that slate fires after it sets its new values.

We tried to do something like this, but to no avail:

    editor.selection = {
      anchor: {
        path: [0],
        offset: 0
      },
      focus: {
        path: [0],
        offset: 0
      }
    };
    editor.children = value;
    editor.selection = selection;

If we were to miss something, please let us know how to save and set value and selector safely.

@ghingis ghingis added the bug label Jun 7, 2021
@PibeG
Copy link

PibeG commented Jun 9, 2021

Try using Transforms.select(editor: Editor, target: Location)
That use case is in the docs: https://docs.slatejs.org/concepts/04-transforms#selection-transforms

@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