forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseKatexStyles.ts
More file actions
27 lines (22 loc) · 777 Bytes
/
Copy pathuseKatexStyles.ts
File metadata and controls
27 lines (22 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"use client";
import { useEffect } from "react";
let injected = false;
/**
* Dynamically injects KaTeX CSS at runtime to avoid the Next.js
* "Global CSS cannot be imported from within node_modules" build error.
*
* Uses a singleton flag so the stylesheet is only injected once.
*/
export function useKatexStyles(): void {
useEffect(() => {
if (injected || typeof document === "undefined") return;
injected = true;
// Dynamic import defers CSS loading to runtime, bypassing
// Next.js static analysis that rejects global CSS from node_modules.
void import("katex/dist/katex.min.css").catch(() => {
console.warn(
"[CopilotKit] Failed to load katex styles — math content may render without formatting",
);
});
}, []);
}