-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
feat(normalize-node): Adding children
field to prevent erronous nodes from breaking notebooks.
#5620
Conversation
…dren undefined` errors
🦋 Changeset detectedLatest commit: 9c31b12 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The |
Thinking about this one, will have some thoughts soon. |
Thank you, I'll be more than happy to put in the work for this one |
I don't have a better suggestion, so let's land it. If it breaks other things we'll revert quickly and revisit. |
Isn't this handled by default? From https://docs.slatejs.org/concepts/11-normalizing:
Making it an empty array as introduced here actually creates an incorrect state. I realized this after part of my app which relied on the original behavior broke:
|
…es from breaking notebooks. (ianstormtaylor#5620) * FEAT: Adding children array to erronous node to prevent various `children undefined` errors * CHORE: Adding changeset
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
.)