From af2a3f42c8d3d90328f329e634ce8f829e33629a Mon Sep 17 00:00:00 2001 From: Linus Flood Date: Tue, 29 Apr 2025 09:38:05 +0000 Subject: [PATCH] Merged in fix/rte-null-check (pull request #1901) fix: null check on nodeChildrenToHtml to avoid rendering empty objects * fix: null check on nodeChildrenToHtml to avoid rendering empty objects Approved-by: Michael Zetterberg Approved-by: Anton Gunnarsson --- .../components/DeprecatedJsonToHtml/utils.tsx | 20 ++++++++++++------- .../components/JsonToHtml/utils.tsx | 20 ++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/apps/scandic-web/components/DeprecatedJsonToHtml/utils.tsx b/apps/scandic-web/components/DeprecatedJsonToHtml/utils.tsx index c87a26a96..c3fb6e3b8 100644 --- a/apps/scandic-web/components/DeprecatedJsonToHtml/utils.tsx +++ b/apps/scandic-web/components/DeprecatedJsonToHtml/utils.tsx @@ -33,13 +33,19 @@ export function nodeChildrenToHtml( embeds: EmbedByUid, fullRenderOptions: RenderOptions ): any { - return nodes.map((node, i) => { - // This function either returns a JSX element or null - return { - ...nodeToHtml(node, embeds, fullRenderOptions), - key: `child-rte-${i}`, - } - }) + return nodes + .map((node, i) => { + // This function either returns a JSX element or null + const element = nodeToHtml(node, embeds, fullRenderOptions) + if (!element) { + return null + } + return { + ...element, + key: `child-rte-${i}`, + } + }) + .filter(Boolean) } export function textNodeToHtml( diff --git a/apps/scandic-web/components/JsonToHtml/utils.tsx b/apps/scandic-web/components/JsonToHtml/utils.tsx index c7b761fa9..c3748a2fb 100644 --- a/apps/scandic-web/components/JsonToHtml/utils.tsx +++ b/apps/scandic-web/components/JsonToHtml/utils.tsx @@ -37,13 +37,19 @@ export function nodeChildrenToHtml( embeds: EmbedByUid, fullRenderOptions: RenderOptions ): any { - return nodes.map((node, i) => { - // This function either returns a JSX element or null - return { - ...nodeToHtml(node, embeds, fullRenderOptions), - key: `child-rte-${i}`, - } - }) + return nodes + .map((node, i) => { + // This function either returns a JSX element or null + const element = nodeToHtml(node, embeds, fullRenderOptions) + if (!element) { + return null + } + return { + ...element, + key: `child-rte-${i}`, + } + }) + .filter(Boolean) } export function textNodeToHtml(