mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-20 06:01:24 +02:00
feat(normalize-node): Adding children
field to prevent erronous nodes from breaking notebooks. (#5620)
* FEAT: Adding children array to erronous node to prevent various `children undefined` errors * CHORE: Adding changeset
This commit is contained in:
5
.changeset/lazy-radios-smile.md
Normal file
5
.changeset/lazy-radios-smile.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'slate': patch
|
||||
---
|
||||
|
||||
Making `normalizeNode` capable of normalizing erronous nodes, making slate more resilient.
|
@@ -75,6 +75,19 @@ export const normalizeNode: WithEditorFirstArg<Editor['normalizeNode']> = (
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If the child is not a text node, and doesn't have a `children` field,
|
||||
// then we have an invalid node that will upset slate.
|
||||
//
|
||||
// eg: `{ type: 'some_node' }`.
|
||||
//
|
||||
// To prevent slate from breaking, we can add the `children` field,
|
||||
// and now that it is valid, we can to many more operations easily,
|
||||
// such as extend normalizers to fix erronous structure.
|
||||
if (!Text.isText(child) && !('children' in child)) {
|
||||
const elementChild = child as Element
|
||||
elementChild.children = []
|
||||
}
|
||||
|
||||
// Merge adjacent text nodes that are empty or match.
|
||||
if (prev != null && Text.isText(prev)) {
|
||||
if (Text.equals(child, prev, { loose: true })) {
|
||||
|
Reference in New Issue
Block a user