From b0de0bd278f1d3d87602d008b51754935e1a5177 Mon Sep 17 00:00:00 2001 From: stekalt <71731085+stekalt@users.noreply.github.com> Date: Tue, 15 Oct 2024 11:40:06 +0200 Subject: [PATCH] Prevent rendering of RichTextBlock without content (#2585) Currently, blocks using the `PreviewSkeleton` are rendered empty in the site if they do not contain any content. This causes unwanted HTML tags in the site. This change prevents these blocks from being rendered without content. --------- Co-authored-by: Stefanie Kaltenhauser Co-authored-by: Johannes Obermair <48853629+johnnyomair@users.noreply.github.com> --- .changeset/wise-mirrors-rescue.md | 10 ++++++++++ .../cms-site/src/previewskeleton/PreviewSkeleton.tsx | 5 +++++ 2 files changed, 15 insertions(+) create mode 100644 .changeset/wise-mirrors-rescue.md diff --git a/.changeset/wise-mirrors-rescue.md b/.changeset/wise-mirrors-rescue.md new file mode 100644 index 0000000000..8e482d084b --- /dev/null +++ b/.changeset/wise-mirrors-rescue.md @@ -0,0 +1,10 @@ +--- +"@comet/cms-site": patch +--- + +Prevent rendering of empty blocks in `PreviewSkeleton` + +Previously, in non-preview environments, `PreviewSkeleton` would still render its children, even if `hasChanges` was set to `false`, causing unwanted empty HTML tags in the site. +For instance, an empty rich text block would still render a `

` tag. +Now, the children will only be rendered if `hasContent` is set to `true`. +Doing so removes the need for duplicate empty checks. diff --git a/packages/site/cms-site/src/previewskeleton/PreviewSkeleton.tsx b/packages/site/cms-site/src/previewskeleton/PreviewSkeleton.tsx index 51fac9e810..b899cd52eb 100644 --- a/packages/site/cms-site/src/previewskeleton/PreviewSkeleton.tsx +++ b/packages/site/cms-site/src/previewskeleton/PreviewSkeleton.tsx @@ -53,6 +53,11 @@ const PreviewSkeleton = ({ ); } } + + if (!hasContent) { + return null; + } + return <>{children}; };