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

Out of range position exception when adding ySyncPlugin to an existing editor #170

Closed
gvergnaud opened this issue Nov 21, 2024 · 0 comments · Fixed by #171
Closed

Out of range position exception when adding ySyncPlugin to an existing editor #170

gvergnaud opened this issue Nov 21, 2024 · 0 comments · Fixed by #171
Assignees
Labels
bug Something isn't working

Comments

@gvergnaud
Copy link
Contributor

Describe the bug

When dynamically adding the ySyncPlugin plugin to an existing editor with a state that doesn't perfectly match the current the Y.XmlFragment state, the ySyncPlugin overrides the editor state to fix this inconsistency (which is expected), and then tries to preserve the user's current selection (here in the code).

This second part can throw an exception if the position is no longer valid for the updated document state.

Screenshot 2024-11-21 at 14 41 32

To Reproduce

You can reproduce this error in this stackblitz sandbox.

Steps to reproduce the behavior:
0. Open the link to the reproduction case.

  1. Start by typing in the editor.
  2. Click on the button. It will add the ySyncPlugin to the editor's list of plugins.
  3. An out-of-bounds error will be thrown.
  4. Open the console to look at the error.

Expected behavior

When applying your previous selection to the new state, ySyncPlugin should clamp it to the range of valid positions of the new document state, to avoid throwing an error.

Environment Information

  • "y-prosemirror": "1.2.12"
  • "yjs": "13.6.20"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants