fixing a bug in closeFragment #11
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix-close-fragment"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
when
fillBeforeis called withtoEnd=true, it won't return a fragment whose match isn't able to go to the end of the content expression. In thiscloseFragmentcode, we've seen a few cases where the code as it stands generates an exception. This should be a simple patch to fix this case, though unfortunately because it has come up in a production app as part of a paste, I don't have a great grasp on a test case that might be able to reproduce the conditions of the bug.In principe, since the fragment passed to fillBefore comes from a node of type parent.type, it should always be possible to complete it. And even if we ignore that, not completing it just produces an invalid node, so that's no solution either.
As such, I really would be interested in the situation that produces this error, since the problem is likely elsewhere.
I think I finally figured out the specific situation where this occurs: we were using the
transformPastedhook, and inadvertently producing a schema-invalid Slice, which got inserted viadoPaste.I know that generally the philosophy of ProseMirror is that you should be responsible for checking schema validity as you go, but is this the right error to expect in a situation where the library is attempting to replace the current selection with a schema-invalid Slice? Should all pasted slices returning from
transformPastedsomehow be schema-validated? I'm happy if the answer is no, but in this case I think it might have been helpful if the error we'd been getting were specifically related to the fact that it stemmed from a schema issue.The approach taken by the library is to assume that it only gets valid pieces of document. Re-checking is somewhat expensive (would have to walk the whole tree and run content expressions against node content), and doing that for everything that comes from user code, which would concern a lot of functions and methods, seems too wasteful.
As such, you can call
checkon nodes if you want to add assertions in your own code, but the library itself doesn't.Pull request closed