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",