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

horizontal-rule extension throws "RangeError: Position x out of range" #2117

Closed
2 tasks done
jakedolan opened this issue Nov 2, 2021 · 5 comments · Fixed by #2147
Closed
2 tasks done

horizontal-rule extension throws "RangeError: Position x out of range" #2117

jakedolan opened this issue Nov 2, 2021 · 5 comments · Fixed by #2147
Labels
Type: Bug The issue or pullrequest is related to a bug

Comments

@jakedolan
Copy link
Contributor

jakedolan commented Nov 2, 2021

What’s the bug you are facing?

The horizontal-rule extension throws a RangeError in certain positions. The reproduction is in an unlikely set of circumstances and/or a position that should be invalid. But I discovered this reproducible case as I have a method checking the editor's commands if they can() at a given time in order to disable the command in the toolbar.

The same error is thrown when either the chained command or can() are executed with setHorizontalRule().

How can we reproduce the bug on our side?

Steps to reproduce (see codesandbox):

  1. Click the 'Add Table' button.
  2. Use the Gap Cursor and click enter to create an empty Paragraph node under the table.
  3. Click the 'Add List' button.
  4. Click the 'Add HR' button. (chained command)
  5. (alternately) Click the 'Can HR' button. (can)

Error will be thrown.

Can you provide a CodeSandbox?

https://codesandbox.io/s/tiptap-horizontal-rule-error-8fzj4?file=/src

What did you expect to happen?

editor.can().setHorizontalRule() would run -- returning a Boolean -- without throwing an error.

editor.chain().focus().setHorizontalRule().run() would run -- inserting or not inserting the horizontal rule -- without throwing an error.

Anything to add? (optional)

The codesandbox uses the starter-kit (throws some deprecation warnings from the bubble/floating menus), but it is reproducible in my production app (using a week old packages) and my dev environment using freshly installed versions of the following.

It may be important to point out that this is using the vue2 package.

├─ @tiptap/core@2.0.0-beta.130
├─ @tiptap/extension-blockquote@2.0.0-beta.21
├─ @tiptap/extension-bold@2.0.0-beta.21
├─ @tiptap/extension-bubble-menu@2.0.0-beta.44
├─ @tiptap/extension-bullet-list@2.0.0-beta.20
├─ @tiptap/extension-code-block@2.0.0-beta.26
├─ @tiptap/extension-code@2.0.0-beta.22
├─ @tiptap/extension-document@2.0.0-beta.13
├─ @tiptap/extension-floating-menu@2.0.0-beta.38
├─ @tiptap/extension-focus@2.0.0-beta.31
├─ @tiptap/extension-gapcursor@2.0.0-beta.30
├─ @tiptap/extension-hard-break@2.0.0-beta.26
├─ @tiptap/extension-heading@2.0.0-beta.20
├─ @tiptap/extension-highlight@2.0.0-beta.27
├─ @tiptap/extension-history@2.0.0-beta.18
├─ @tiptap/extension-horizontal-rule@2.0.0-beta.26
├─ @tiptap/extension-italic@2.0.0-beta.21
├─ @tiptap/extension-link@2.0.0-beta.25
├─ @tiptap/extension-list-item@2.0.0-beta.16
├─ @tiptap/extension-mention@2.0.0-beta.81
├─ @tiptap/extension-ordered-list@2.0.0-beta.21
├─ @tiptap/extension-paragraph@2.0.0-beta.19
├─ @tiptap/extension-placeholder@2.0.0-beta.38
├─ @tiptap/extension-strike@2.0.0-beta.23
├─ @tiptap/extension-subscript@2.0.0-beta.6
├─ @tiptap/extension-superscript@2.0.0-beta.6
├─ @tiptap/extension-table-cell@2.0.0-beta.17
├─ @tiptap/extension-table-header@2.0.0-beta.19
├─ @tiptap/extension-table-row@2.0.0-beta.16
├─ @tiptap/extension-table@2.0.0-beta.37
├─ @tiptap/extension-task-item@2.0.0-beta.24
├─ @tiptap/extension-task-list@2.0.0-beta.20
├─ @tiptap/extension-text-align@2.0.0-beta.25
├─ @tiptap/extension-text@2.0.0-beta.13
├─ @tiptap/extension-typography@2.0.0-beta.17
├─ @tiptap/extension-underline@2.0.0-beta.18
├─ @tiptap/suggestion@2.0.0-beta.77
└─ @tiptap/vue-2@2.0.0-beta.62

Did you update your dependencies?

  • Yes, I’ve updated my dependencies to use the latest version of all packages.

Are you sponsoring us?

  • Yes, I’m a sponsor. 💖
@jakedolan jakedolan added the Type: Bug The issue or pullrequest is related to a bug label Nov 2, 2021
@duhaime
Copy link

duhaime commented Feb 5, 2022

@philippkuehn is there any chance you could say a little bit about what this error indicates? I have just experienced the same error and it made my editor state completely corrupt.

I have not been able to reproduce it since, but knowing what the error means may help me reproduce it...

@philippkuehn
Copy link
Contributor

@duhaime Assuming your document has a size of 100 and you want to update position 101, you will see this error. Most of the time, the reason is that positions are not mapped correctly when you work with an old and a new state.

@duhaime
Copy link

duhaime commented Feb 6, 2022

Thank you! I found an edge case where the mentions plugin can generate one of these consistently. If it looks like there's something we can patch in the core I'll follow up (likely I've mangled something in my extensions of the Mention)

@philippkuehn
Copy link
Contributor

@duhaime Maybe this has been fixed already by this patch: #2413 (comment)

@duhaime
Copy link

duhaime commented Feb 6, 2022

@philippkuehn ah that could be! Is that patch deployed on https://tiptap.dev/api/nodes/mention?

I created #2490 to discuss the reproducible scenario that will trigger this exception...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug The issue or pullrequest is related to a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants