tiptap
tiptap copied to clipboard
Input rules cause issues when `renderText` produces text that is matched by the input rule
What’s the bug you are facing?
When renderText
in a custom node produces text that is matched by a input rule, a position out of range error is triggered.
Our use case is to have dynamic nodes whose content is determined by an object of values at runtime. The node has a property name that it uses to pull off the value from that object. It's important for us that the text representation and the input rules are exactly the same.
Which browser was this experienced in? Are any special extensions installed?
chrome, no relevant extensions
How can we reproduce the bug on our side?
- Create a node with a
renderText
that outputs some text (ie 'custom-node') - Add a node input rule that replaces the text with the node (ie
/custom-node/
) - In the editor, type the text that matches rule, that should work
- Type it again, that should fail with the error
Can you provide a CodeSandbox?
This is primitive and non-sensical, but demonstrates the behavior: https://codesandbox.io/s/tender-hill-l74pkp
What did you expect to happen?
I would expect that node input rules should only process text nodes and not other custom nodes. Or at least be able to filter them out when matching.
Anything to add? (optional)
No response
Did you update your dependencies?
- [X] Yes, I’ve updated my dependencies to use the latest version of all packages.
Are you sponsoring us?
- [X] Yes, I’m a sponsor. 💖
FWIW: this was working in @tiptap/[email protected], but it is broken in 2.0.0-beta.181
@arrocke Thanks for your report. There are some known issues with the input rules. If you have a change, could you give https://github.com/ueberdosis/tiptap/pull/2941 a try and see if this is affect your case?
I don't think it will. Since my custom node has renderText
defined, toText
will execute before $from.nodeBefore?.text
does
@svenadlung I wanted to add this here rather than create a new issue because I believe they are still related. Input rules still don't work quite right even after your most recent fix. Thanks for being prompt and getting right on that, by the way.
The new problem has to do with your fix. It seems like sometimes the same text nodes are being added to textBefore
multiple times. You can see this behavior here. After the first equation, you can see a capital X. If you put dollar signs around that ($X$) you'll see that it repeats the same text several times. I have confirmed that that is the result of textBefore
coming from the getTextContentFromNodes
function. The iteration you are doing in there is iterating over the same nodes multiple times.
An alternative to your approach may be to just do what ProseMirror does. The equivalent line of code ProseMirror is
let textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - MAX_MATCH), $from.parentOffset,
null, "\ufffc") + text
You can see the full code in this discussion
Hope this helps the triage.
Oh, I also went back to @tiptap/[email protected] and input rules were still working correctly there.
This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 7 days
Wondering if there is timeline for a fix on this? It's preventing us from upgrading to get fixes for other issues.
This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 7 days
This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 7 days
This is still an issue as far as I am aware