Skip to content

Commit 28cffbf

Browse files
committed
chore: remove isomorphic-dompurify and add sanitize-html with types
1 parent 775b5c8 commit 28cffbf

4 files changed

Lines changed: 69 additions & 570 deletions

File tree

app/(app)/articles/[slug]/page.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { getPost } from "@/server/lib/posts";
1616
import { getCamelCaseFromLower } from "@/utils/utils";
1717
import { generateHTML } from "@tiptap/core";
1818
import { TiptapExtensions } from "@/components/editor/editor/extensions";
19-
import DOMPurify from "isomorphic-dompurify";
19+
import sanitizeHtml from "sanitize-html";
2020
import type { JSONContent } from "@tiptap/core";
2121
import NotFound from "@/components/NotFound/NotFound";
2222

@@ -74,8 +74,26 @@ const parseJSON = (str: string): JSONContent | null => {
7474

7575
const renderSanitizedTiptapContent = (jsonContent: JSONContent) => {
7676
const rawHtml = generateHTML(jsonContent, [...TiptapExtensions]);
77-
// Sanitize the HTML
78-
return DOMPurify.sanitize(rawHtml);
77+
// Sanitize the HTML using sanitize-html (server-safe, no jsdom dependency)
78+
return sanitizeHtml(rawHtml, {
79+
allowedTags: sanitizeHtml.defaults.allowedTags.concat([
80+
"img",
81+
"iframe",
82+
"h1",
83+
"h2",
84+
]),
85+
allowedAttributes: {
86+
...sanitizeHtml.defaults.allowedAttributes,
87+
img: ["src", "alt", "title", "width", "height", "class"],
88+
iframe: ["src", "width", "height", "frameborder", "allowfullscreen"],
89+
"*": ["class", "id", "style"],
90+
},
91+
allowedIframeHostnames: [
92+
"www.youtube.com",
93+
"youtube.com",
94+
"www.youtube-nocookie.com",
95+
],
96+
});
7997
};
8098

8199
const ArticlePage = async (props: Props) => {

next.config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ const REMOTE_PATTERNS = [
2020
}));
2121

2222
const config = {
23-
// Exclude jsdom and isomorphic-dompurify from bundling to fix ESM/CJS compatibility
24-
serverExternalPackages: ["jsdom", "isomorphic-dompurify"],
2523
// Turbopack configuration for SVGR (replaces webpack config)
2624
turbopack: {
2725
rules: {

0 commit comments

Comments
 (0)