From 9921b00dd82c3c4efd8fce331ef072add37f0b43 Mon Sep 17 00:00:00 2001 From: strasmus1 Date: Tue, 19 May 2026 08:24:14 +0000 Subject: [PATCH] Fix empty style attr handling for Impressum --- .../data/migrations/00045_fix_impressum_style_attribute.sql | 4 ++++ gradesa/src/app/api/pages/[type]/[slug]/route.js | 2 +- gradesa/src/components/ui/render-html/render-html.jsx | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 gradesa/data/migrations/00045_fix_impressum_style_attribute.sql diff --git a/gradesa/data/migrations/00045_fix_impressum_style_attribute.sql b/gradesa/data/migrations/00045_fix_impressum_style_attribute.sql new file mode 100644 index 0000000..71ce679 --- /dev/null +++ b/gradesa/data/migrations/00045_fix_impressum_style_attribute.sql @@ -0,0 +1,4 @@ +-- Remove empty style attribute that caused React errors on the Impressum page +UPDATE html_pages +SET content = REPLACE(content, 'style=""', '') +WHERE page_group = 'system' AND slug = 'impressum'; diff --git a/gradesa/src/app/api/pages/[type]/[slug]/route.js b/gradesa/src/app/api/pages/[type]/[slug]/route.js index b157366..33dd5c0 100644 --- a/gradesa/src/app/api/pages/[type]/[slug]/route.js +++ b/gradesa/src/app/api/pages/[type]/[slug]/route.js @@ -98,7 +98,7 @@ function sanitize(data) { const window = new JSDOM("").window; const purify = DOMPurify(window); const cleaned = purify.sanitize(data, { ADD_ATTR: ["target"] }); - return cleaned; + return cleaned.replace(/\s+style=""/g, ""); } async function slugIsInUse(type, slug) { diff --git a/gradesa/src/components/ui/render-html/render-html.jsx b/gradesa/src/components/ui/render-html/render-html.jsx index a6ff947..e7a5d0e 100644 --- a/gradesa/src/components/ui/render-html/render-html.jsx +++ b/gradesa/src/components/ui/render-html/render-html.jsx @@ -63,6 +63,10 @@ const prefixRootRelativePath = (value) => { export default function RenderHTML({ data, disableGlossary = false }) { if (!data) return null; + // Strip empty style attributes before parsing so React does not receive + // an invalid string value for the style prop. + const cleanedData = data.replace(/\s+style=""/g, ""); + const renderParagraph = (attributes, children) => disableGlossary ? (

{children}

@@ -135,6 +139,6 @@ export default function RenderHTML({ data, disableGlossary = false }) { return handler ? handler(normalizedAttributes, children) : undefined; }; - const parsedContent = parse(data, { replace: replacer }); + const parsedContent = parse(cleanedData, { replace: replacer }); return
{parsedContent}
; }