diff --git a/src/utils/MessageDiffUtils.tsx b/src/utils/MessageDiffUtils.tsx index f8b638617a..6d261052fd 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 aec4f6cfae..b2721b2a32 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 ddbfea091e..655fc8a807 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`] = ` +