Skip to content

Commit

Permalink
#3762: Fix empty html bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
anilsonmez-simsoft committed Oct 13, 2021
1 parent b7bfc7e commit 242285c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions client/src/components/RichTextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,18 @@ const serialize = node => {
}

const deserialize = element => {
const children = Array.from(element.childNodes).map(deserialize)
let children = Array.from(element.childNodes).map(deserialize)
// Body must have at least one children node for user to be able to edit the text in it
// Every other node must have a non-empty array of children
if (element.nodeName !== "#text" && _isEmpty(children)) {
children =
element.nodeName === "BODY"
? jsx("element", { type: "paragraph" }, [{ text: "" }])
: [{ text: "" }]
}

switch (element.nodeName) {
case "BODY":
// Body must have at least one children node for user to be able to edit the text in it
if (_isEmpty(children)) {
return jsx(
"fragment",
{},
jsx("element", { type: "paragraph" }, [{ text: "" }])
)
}
return jsx("fragment", {}, children)
case "P":
return jsx("element", { type: "paragraph" }, children)
Expand Down

0 comments on commit 242285c

Please sign in to comment.