feat(normalize-node): Adding children
field to prevent erronous nodes from breaking notebooks.
#5620
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Sometimes, when working with other tools such as Yjs, it so happens that we enter nodes into
editor.children
that slate cannot recover from. The most common case I come across is erronous nodes that are elements, and somewhere along the process thechildren
field was dropped.This could happen for various reasons, but IMO slate should be able to recover from them.
Example
Let's say you have the following:
Using
editor.normalize
won't touch thenot_row
element, but if you attempteditor.normalize({ force: true })
, slate will throw an error, and rightfully so.This at least prepares the node, making it acceptable by
Element.isElement
, and allowing normalizer plugins the user might make, to easily normalize away these nodes, because otherwise they will not be able to be normalized.Disclaimer
I've used Slate for a while, and I know a fair bit about it. But this could have missed the mark.
The way in which I do this doesn't seem ideal to me. It seems like an anti-pattern. But using the
Transforms
will result in the same error being thrown, because we assume that thisNode
has achildren
field.Any help would be greatly appreciated.
Checks
yarn test
.yarn lint
. (Fix errors withyarn fix
.)yarn start
.)yarn changeset add
.)