From 41c96877d3948a15fb617db16f5d315b466dbb72 Mon Sep 17 00:00:00 2001 From: Kerry Date: Thu, 11 May 2023 22:21:02 +1200 Subject: [PATCH] Fix: Edit history modal crash (#10834) * failing test * handle nodes without children in messagediffutils --- src/utils/MessageDiffUtils.tsx | 6 ++-- test/utils/MessageDiffUtils-test.tsx | 1 + .../MessageDiffUtils-test.tsx.snap | 31 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) 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`] = ` +
+ + + + + hi + +
+

+

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