react-ai-renderer 0.1.11 → 0.1.14

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
@@ -68,6 +68,9 @@ npm install mermaid
68
68
 
69
69
  ## 🎯 快速开始
70
70
 
71
+ > 💡 **开发调试?** 查看 [开发模式使用指南](./DEVELOPMENT.md) 了解如何在本地开发和调试本库。
72
+ > 🔥 **使用监听模式开发?** 运行 `npm run watch` 启动自动监听和重新构建,修改代码后自动更新!
73
+
71
74
  ### 基础使用
72
75
 
73
76
  ```tsx
@@ -310,63 +313,52 @@ graph TD
310
313
  4. Component Renderer 渲染自定义 UI 组件
311
314
  5. 触发生命周期钩子,执行后续动作
312
315
 
313
- ## ⚠️ Next.js 使用注意事项
314
-
315
- 本库已针对 Next.js 的服务端渲染(SSR)进行了优化。在使用时需要注意:
316
-
317
- ### 动态导入以避免 SSR 问题
318
-
319
- 对于包含复杂渲染逻辑的页面,建议使用动态导入(仅在客户端加载):
320
-
321
- ```tsx
322
- import dynamic from 'next/dynamic';
316
+ ## 🔧 Next.js 集成
323
317
 
324
- const ReactAIRenderer = dynamic(() => import('react-ai-renderer'), {
325
- ssr: false, // 禁用服务端渲染
326
- loading: () => <div>加载中...</div>
327
- });
328
- ```
318
+ 本库已完全兼容 Next.js 的服务器端渲染(SSR)。
329
319
 
330
- ### 或者使用 NoSSR 包装器
320
+ ### Next.js 中使用
331
321
 
332
322
  ```tsx
333
- import dynamic from 'next/dynamic';
323
+ // app/your-page/page.tsx pages/your-page.tsx
324
+ import ReactAIRenderer from 'react-ai-renderer';
334
325
 
335
- const ReactAIRenderer = dynamic(() => import('react-ai-renderer'), {
336
- ssr: false
337
- });
326
+ export default function YourPage() {
327
+ const content = `
328
+ # 你好,Next.js!
338
329
 
339
- function App() {
330
+ 这是一个在 Next.js 中使用 React AI Renderer 的示例。
331
+ `;
332
+
340
333
  return (
341
- <ReactAIRenderer>
342
- {content}
343
- </ReactAIRenderer>
334
+ <div>
335
+ <ReactAIRenderer>{content}</ReactAIRenderer>
336
+ </div>
344
337
  );
345
338
  }
346
-
347
- export default dynamic(() => Promise.resolve(App), {
348
- ssr: false
349
- });
350
339
  ```
351
340
 
352
- ### Next.js 客户端组件(推荐)
341
+ ### 需要客户端组件的场景
353
342
 
354
- 使用 Next.js 13+ 的 App Router 时,确保使用 'use client' 指令:
343
+ 如果需要在 Next.js 13+ 的 App Router 中使用交互式组件(如按钮点击等),需要使用 `'use client'` 指令:
355
344
 
356
345
  ```tsx
346
+ // app/your-page/client-renderer.tsx
357
347
  'use client';
358
348
 
359
349
  import ReactAIRenderer from 'react-ai-renderer';
360
350
 
361
- export default function MyPage() {
362
- return (
363
- <ReactAIRenderer>
364
- {content}
365
- </ReactAIRenderer>
366
- );
351
+ export default function ClientAIRenderer({ content }: { content: string }) {
352
+ return <ReactAIRenderer>{content}</ReactAIRenderer>;
367
353
  }
368
354
  ```
369
355
 
356
+ ### 注意事项
357
+
358
+ - ✅ 本库已添加 SSR 安全检查,不会在服务器端访问 `document` 或 `window` 对象
359
+ - ✅ 可以在服务器端安全使用,无需额外配置
360
+ - ✅ 动态功能(如 Mermaid 图表)会自动在客户端渲染
361
+
370
362
  ## ❓ 常见问题
371
363
 
372
364
  ### Q: React AI Renderer 与 react-markdown 有什么区别?
@@ -378,8 +370,8 @@ A: 未注册的组件会自动转换为对应的文本表示形式,不会导
378
370
  ### Q: 是否支持不同组件库如antd,shadcn等
379
371
  A: 是的,React AI Renderer 无组件依赖,你可以使用任意组件库以及自定义组件
380
372
 
381
- ### Q: 在 Next.js 中使用时遇到 "document is not defined" 错误?
382
- A: 使用动态导入(`dynamic import`)或 `'use client'` 指令来确保组件只在客户端渲染。
373
+ ### Q: 在 Next.js 中出现 "document is not defined" 错误怎么办?
374
+ A: 请确保使用最新版本(v0.1.12+),该版本已完全修复 SSR 兼容性问题。如果仍有问题,请检查是否正确安装了依赖并清理 Next.js 缓存。
383
375
 
384
376
  ### Q: 性能如何优化?
385
377
  A: 建议合理使用组件生命周期钩子,避免在渲染过程中执行耗时操作。