diff --git a/src/utils/MessageDiffUtils.tsx b/src/utils/MessageDiffUtils.tsx index f8b638617a9..6d261052fd1 100644 --- a/src/utils/MessageDiffUtils.tsx +++ b/src/utils/MessageDiffUtils.tsx @@ -104,8 +104,10 @@ function diffTreeToDOM(desc: Text | HTMLElement): Node { for (const [key, value] of Object.entries(desc.attributes)) { node.setAttribute(key, value.value); } - for (const childDesc of desc.childNodes) { - node.appendChild(diffTreeToDOM(childDesc as Text | HTMLElement)); + if (desc.childNodes) { + for (const childDesc of desc.childNodes) { + node.appendChild(diffTreeToDOM(childDesc as Text | HTMLElement)); + } } return node; } diff --git a/test/utils/MessageDiffUtils-test.tsx b/test/utils/MessageDiffUtils-test.tsx index aec4f6cfaed..b2721b2a323 100644 --- a/test/utils/MessageDiffUtils-test.tsx +++ b/test/utils/MessageDiffUtils-test.tsx @@ -49,6 +49,7 @@ describe("editBodyDiffToHtml", () => { ["attribute modifications", `hi`, `hi`], ["attribute deletions", `hi`, `hi`], ["attribute additions", `hi`, `hi`], + ["handles empty tags", `hi`, `

hi`], ])("renders %s", (_label, before, after) => { const { container } = renderDiff(before, after); expect(container).toMatchSnapshot(); diff --git a/test/utils/__snapshots__/MessageDiffUtils-test.tsx.snap b/test/utils/__snapshots__/MessageDiffUtils-test.tsx.snap index ddbfea091e1..655fc8a8077 100644 --- a/test/utils/__snapshots__/MessageDiffUtils-test.tsx.snap +++ b/test/utils/__snapshots__/MessageDiffUtils-test.tsx.snap @@ -365,6 +365,37 @@ exports[`editBodyDiffToHtml renders element replacements 1`] = ` `; +exports[`editBodyDiffToHtml renders handles empty tags 1`] = ` +
+ + + + + hi + +
+

+

+
+
+ + hi + +
+
+`; + exports[`editBodyDiffToHtml renders inline element additions 1`] = `