react-ai-renderer 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -58,23 +58,6 @@ yarn add react-ai-renderer
58
58
 
59
59
  ### 可选依赖
60
60
 
61
- #### 1. KaTeX(数学公式渲染)
62
-
63
- 本库支持使用 KaTeX 渲染数学公式,但需要在你的项目中手动导入 CSS:
64
-
65
- **在 _app.tsx 或全局样式文件中添加:**
66
- ```tsx
67
- import 'katex/dist/katex.min.css';
68
- ```
69
-
70
- **Next.js 项目中:**
71
- ```tsx
72
- // pages/_app.tsx 或 app/layout.tsx
73
- import 'katex/dist/katex.min.css';
74
- ```
75
-
76
- #### 2. Mermaid(图表渲染)
77
-
78
61
  本库支持渲染 Mermaid 图表,但需要安装额外的依赖:
79
62
 
80
63
  ```bash
@@ -327,6 +310,63 @@ graph TD
327
310
  4. Component Renderer 渲染自定义 UI 组件
328
311
  5. 触发生命周期钩子,执行后续动作
329
312
 
313
+ ## ⚠️ Next.js 使用注意事项
314
+
315
+ 本库已针对 Next.js 的服务端渲染(SSR)进行了优化。在使用时需要注意:
316
+
317
+ ### 动态导入以避免 SSR 问题
318
+
319
+ 对于包含复杂渲染逻辑的页面,建议使用动态导入(仅在客户端加载):
320
+
321
+ ```tsx
322
+ import dynamic from 'next/dynamic';
323
+
324
+ const ReactAIRenderer = dynamic(() => import('react-ai-renderer'), {
325
+ ssr: false, // 禁用服务端渲染
326
+ loading: () => <div>加载中...</div>
327
+ });
328
+ ```
329
+
330
+ ### 或者使用 NoSSR 包装器
331
+
332
+ ```tsx
333
+ import dynamic from 'next/dynamic';
334
+
335
+ const ReactAIRenderer = dynamic(() => import('react-ai-renderer'), {
336
+ ssr: false
337
+ });
338
+
339
+ function App() {
340
+ return (
341
+ <ReactAIRenderer>
342
+ {content}
343
+ </ReactAIRenderer>
344
+ );
345
+ }
346
+
347
+ export default dynamic(() => Promise.resolve(App), {
348
+ ssr: false
349
+ });
350
+ ```
351
+
352
+ ### Next.js 客户端组件(推荐)
353
+
354
+ 使用 Next.js 13+ 的 App Router 时,确保使用 'use client' 指令:
355
+
356
+ ```tsx
357
+ 'use client';
358
+
359
+ import ReactAIRenderer from 'react-ai-renderer';
360
+
361
+ export default function MyPage() {
362
+ return (
363
+ <ReactAIRenderer>
364
+ {content}
365
+ </ReactAIRenderer>
366
+ );
367
+ }
368
+ ```
369
+
330
370
  ## ❓ 常见问题
331
371
 
332
372
  ### Q: React AI Renderer 与 react-markdown 有什么区别?
@@ -338,6 +378,9 @@ A: 未注册的组件会自动转换为对应的文本表示形式,不会导
338
378
  ### Q: 是否支持不同组件库如antd,shadcn等
339
379
  A: 是的,React AI Renderer 无组件依赖,你可以使用任意组件库以及自定义组件
340
380
 
381
+ ### Q: 在 Next.js 中使用时遇到 "document is not defined" 错误?
382
+ A: 使用动态导入(`dynamic import`)或 `'use client'` 指令来确保组件只在客户端渲染。
383
+
341
384
  ### Q: 性能如何优化?
342
385
  A: 建议合理使用组件生命周期钩子,避免在渲染过程中执行耗时操作。
343
386