-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[Bug]: Invalid content doesn't cause error #5500
Comments
So what To check for that, it is a pretty easy change: diff --git a/packages/core/src/helpers/createNodeFromContent.ts b/packages/core/src/helpers/createNodeFromContent.ts
index 7fe83f83c..63a9a2f9d 100644
--- a/packages/core/src/helpers/createNodeFromContent.ts
+++ b/packages/core/src/helpers/createNodeFromContent.ts
@@ -45,7 +45,13 @@ export function createNodeFromContent(
return Fragment.fromArray(content.map(item => schema.nodeFromJSON(item)))
}
- return schema.nodeFromJSON(content)
+ const node = schema.nodeFromJSON(content)
+
+ if (options.errorOnInvalidContent) {
+ node.check()
+ }
+
+ return node
} catch (error) {
if (options.errorOnInvalidContent) {
throw new Error('[tiptap error]: Invalid JSON content', { cause: error as Error }) But this will still show the invalid content, ideally prosemirror would just skip over any content that it considers invalid and allows you to display the rest. But it only throws an error right now saying that the node nesting is invalid. This will require some more thought |
Thank you for your answer. I didn't know about the node.check() function. My use case is only concerned with detecting invalid content and not with its display, so your answer is a great help to me and already resolves my issues. |
If that is the case, I would be happy to accept a PR with this change, it requires minimal work on our side and I think matches user expectation with |
Do you want me to submit that PR? |
That would be great @lepult |
This has been released with 2.7.0-pre.0 and will be released in tiptap 2.7.0 when this beta has been tested by more users |
Affected Packages
core, paragraph
Version(s)
2.6.3
Bug Description
Content that doesn't follow the schema can be set with no errors.
Browser Used
Firefox
Code Example URL
https://codesandbox.io/p/sandbox/friendly-leaf-ksgwwk
Expected Behavior
In the sandbox the Tiptap content is set to a Paragraph that contains a HorizontalRule and another Paragraph. This content is invalid, since the schema of Paragraph is 'inline*', while both Paragraph and HorizontalRule are 'block' nodes.
Despite that, the content is set without error and the invalid content is displayed. After you type something and redo that change (CTRL+Z) an error is thrown (when you write in the first line, the error is thrown instantly). Why is that error only thrown after changes and not when the content is set?
Additional Context (Optional)
This is the result of editor.getJSON() after initialisation of the editor. You can see how the content is invalid, since there is a Paragraph and a HorizontalRule within the Paragraph.
Dependency Updates
The text was updated successfully, but these errors were encountered: