From f34f073d1ea8bda0f07e4e647c71aed99d623c5f Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Mon, 10 Aug 2026 09:52:17 +0900 Subject: [PATCH] =?UTF-8?q?260810=5F03=5FENH:=20=EC=97=90=EB=94=94?= =?UTF-8?q?=ED=84=B0=20=EB=B2=84=EC=A0=84=20=EB=A7=9E=EC=B6=A4,=20ssr?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=A1=B0=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- .../kri-editor/KriEditorHtmlOnly.tsx | 6 ++++- .../kri-editor/utils/sanitizeHtml.ts | 22 +++++++++++++++++-- registry/components/registry.json | 2 +- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index c0f76e7..6569fba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kri-ui-registry", - "version": "0.11.0", + "version": "0.11.1", "private": true, "description": "KRI internal shadcn UI registry", "scripts": { diff --git a/registry/components/kri-editor/KriEditorHtmlOnly.tsx b/registry/components/kri-editor/KriEditorHtmlOnly.tsx index 8475fda..ff59ea6 100644 --- a/registry/components/kri-editor/KriEditorHtmlOnly.tsx +++ b/registry/components/kri-editor/KriEditorHtmlOnly.tsx @@ -8,6 +8,7 @@ import { resolveUploadUrl } from './types' import { compressImage } from './utils/imageCompression' import { useDebouncedChange } from './hooks/useDebouncedChange' import { sanitizeHtmlForPreview } from './utils/sanitizeHtml' +import { preserveEmptyParagraphs } from './utils/emptyParagraph' import { useTextareaInsert } from './hooks/useTextareaInsert' type HtmlOnlyProps = Omit & { mode: 'html' } @@ -121,7 +122,10 @@ export function KriEditorHtmlOnly({ } } - const previewHtml = React.useMemo(() => sanitizeHtmlForPreview(html), [html]) + const previewHtml = React.useMemo( + () => sanitizeHtmlForPreview(preserveEmptyParagraphs(html)), + [html], + ) return (
diff --git a/registry/components/kri-editor/utils/sanitizeHtml.ts b/registry/components/kri-editor/utils/sanitizeHtml.ts index 720a9b2..24aa87f 100644 --- a/registry/components/kri-editor/utils/sanitizeHtml.ts +++ b/registry/components/kri-editor/utils/sanitizeHtml.ts @@ -1,12 +1,21 @@ "use client"; -import DOMPurify from "dompurify"; +import DOMPurify, { type DOMPurify as DOMPurifyInstance } from "dompurify"; export type SanitizeHtmlOptions = { tags?: string[]; attributes?: string[]; }; +// Next.js SSR(Node) 환경에서는 dompurify가 window에 바인딩된 인스턴스가 아니라 +// (window: Window) => DOMPurify 형태의 factory만 노출한다. window가 없으면 +// factory를 호출할 방법이 없으므로, 여기서 안전하게 null로 폴백한다. +function resolvePurifier(): DOMPurifyInstance | null { + if (typeof window === "undefined") return null; + if (typeof DOMPurify.sanitize === "function") return DOMPurify; + return DOMPurify(window); +} + export function sanitizeHtml( input: string, options?: SanitizeHtmlOptions, @@ -15,7 +24,16 @@ export function sanitizeHtml( return ""; } - return DOMPurify.sanitize( + const purifier = resolvePurifier(); + + if (!purifier) { + // DOM이 없어 실제 sanitize를 수행할 수 없는 환경(SSR 등)에서는 + // 검증되지 않은 HTML을 그대로 노출하지 않도록 태그를 모두 제거한 텍스트만 반환한다. + // 브라우저에서 하이드레이션된 이후 재계산될 때 실제 sanitize 결과로 대체된다. + return input.replace(/<[^>]*>/g, ""); + } + + return purifier.sanitize( input, { USE_PROFILES: { diff --git a/registry/components/registry.json b/registry/components/registry.json index 0994c14..a88a442 100644 --- a/registry/components/registry.json +++ b/registry/components/registry.json @@ -329,7 +329,7 @@ ], "dependencies": [ "@tiptap/extension-color", - "@tiptap/extension-font-family", + "@tiptap/extension-font-family@3.27.1", "@tiptap/extension-highlight", "@tiptap/extension-image", "@tiptap/extension-link",