From 6a219c7ca5df881354a6937cf28d8a0396bbf8ee Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Wed, 10 May 2023 09:43:07 +1200 Subject: [PATCH 1/2] failing test --- test/utils/MessageDiffUtils-test.tsx | 1 + 1 file changed, 1 insertion(+) 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(); From 060b5af8ab10abb99b9a4a913acd04514b72a9ed Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Wed, 10 May 2023 09:58:58 +1200 Subject: [PATCH 2/2] handle nodes without children in messagediffutils --- src/utils/MessageDiffUtils.tsx | 6 ++-- .../MessageDiffUtils-test.tsx.snap | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) 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/__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`] = `