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

Return pos if descObj.parent is null #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

egwoo
Copy link

@egwoo egwoo commented Feb 3, 2022

In the example at https://tiptap.dev/api/nodes/task-item if you try to click the checkbox to toggle the todo item, you get a console error message:

Uncaught RangeError: Index 1 out of range for <taskList(taskItem(paragraph("A list item")), taskItem(paragraph("And another one")))>
    at F.child (vendor.248662a3.js:5:26763)
    at F.findIndex (vendor.248662a3.js:5:27448)
    at Me.nodeAt (vendor.248662a3.js:5:40931)
    at index.8f971c3d.js:1:2515
    at tabindex.0101c1e1.js:3:1741
    at Object.command (tabindex.0101c1e1.js:3:24344)
    at HTMLInputElement.<anonymous> (index.8f971c3d.js:1:2476)

Looking into this, it looks like descObj exists, but descObj.parent is null, so the function returns nothing. When I changed the return value to pos, it started working again.

In the example at https://tiptap.dev/api/nodes/task-item if you try to click the checkbox to toggle the todo item, you get a console error message:
```
Uncaught RangeError: Index 1 out of range for <taskList(taskItem(paragraph("A list item")), taskItem(paragraph("And another one")))>
    at F.child (vendor.248662a3.js:5:26763)
    at F.findIndex (vendor.248662a3.js:5:27448)
    at Me.nodeAt (vendor.248662a3.js:5:40931)
    at index.8f971c3d.js:1:2515
    at tabindex.0101c1e1.js:3:1741
    at Object.command (tabindex.0101c1e1.js:3:24344)
    at HTMLInputElement.<anonymous> (index.8f971c3d.js:1:2476)
```

Looking into this, it looks like descObj exists, but descObj.parent is null, so the function returns nothing. When I changed the return value to `pos`, it started working again.
@marijnh
Copy link
Member

marijnh commented Feb 4, 2022

It looks like that could only happen when you call getPos after your node view is no longer part of the document. At that point, there is no meaningful document position for it so it seems that returning pos (the original position at which the node view was created) is just going to cover up a deeper problem, and probably not actually do the right thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants