mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
fix: ensure JSDOM is only loaded in server-side environments
This commit is contained in:
@@ -15,9 +15,11 @@ export async function parseMarkdown(md: string): Promise<string> {
|
|||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
dom = window as unknown as WindowLike & { document: Document };
|
dom = window as unknown as WindowLike & { document: Document };
|
||||||
} else {
|
} else if (import.meta.env.SSR) {
|
||||||
const { JSDOM } = await import('jsdom');
|
const { JSDOM } = await import('jsdom');
|
||||||
dom = new JSDOM('').window as unknown as WindowLike & { document: Document };
|
dom = new JSDOM('').window as unknown as WindowLike & { document: Document };
|
||||||
|
} else {
|
||||||
|
throw new Error('JSDOM should only be loaded on the server');
|
||||||
}
|
}
|
||||||
|
|
||||||
const DOMPurify = createDOMPurify(dom);
|
const DOMPurify = createDOMPurify(dom);
|
||||||
|
|||||||
Reference in New Issue
Block a user