Skip to content

Commit

Permalink
feat(normalize-node): Adding children field to prevent erronous nod…
Browse files Browse the repository at this point in the history
…es from breaking notebooks. (ianstormtaylor#5620)

* FEAT: Adding children array to erronous node to prevent various `children undefined` errors

* CHORE: Adding changeset
  • Loading branch information
JohnCosta27 authored Apr 1, 2024
1 parent fa0578f commit 39469df
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/core/normalize-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })) {
Expand Down

0 comments on commit 39469df

Please sign in to comment.