Компоненты
- Accordion
- Alert
- Alert Dialog
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Button
- Calendar
- Card
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- Command
- Date Picker
- Dialog
- DrawerNew
- Empty
- Field
- Fieldset
- Form
- Frame
- Group
- Input
- Input Group
- Kbd
- Label
- Menu
- Meter
- Number Field
- OTP FieldNew
- Pagination
- Popover
- Preview Card
- Progress
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Skeleton
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Toolbar
- Tooltip
AI Components
- AI Components
- Chat Conversation
- Chat Message
- Chat Response
- Chat Suggestion
- Chat Prompt Input
- Chat Attachments
- Chat Code Block
- Chat Image
- Chat Inline Citation
- Chat Reasoning
- Chat Sources
- Chat Actions
- Chat Context
- Chat Loader
- Chat Task
- Chat Tool
- Chat Web Preview
- Chat Snippet
- Chat Terminal
- Chat Stack Trace
- Chat Test Results
- Chat File Tree
- Chat Environment Variables
- Chat Audio Player
- Chat Transcription
- Chat Speech Input
- Chat Mic Selector
- Chat Voice Selector
- Chat Agent
- Chat Persona
- Chat Connection
- Chat Queue
- Chat Checkpoint
- Chat Confirmation
- Chat Artifact
- Chat JSX Preview
- Chat Schema Display
- Chat Package Info
- Chat Commit
- Chat Plan
- Chat Panel
- Chat Open In Chat
- Chat Sandbox
- Chat Model Selector
- Chat Canvas
- Chat Node
- Chat Edge
Resources
Chat JSX Preview
Inline-рендер JSX-строки от модели с auto-close незакрытых тэгов при streaming.
Streaming… auto-closes pending tags as they arrive.
"use client";
import { useEffect, useState } from "react";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { ChatJsxPreview } from "@/components/ui/chat-jsx-preview";
const final = `<div className="flex flex-col gap-3 rounded-xl border p-4 bg-card">
<div className="flex items-center justify-between">
<h3 className="font-semibold text-base">Cache Components</h3>
<Badge variant="secondary">New</Badge>
</div>
<p className="text-muted-foreground text-sm">
Cache the rendered output of any Server Component with the
<code>"use cache"</code> directive.
</p>
<div className="flex items-center gap-2">
<Button size="sm">Read docs</Button>
<Button size="sm" variant="outline">Try it</Button>
</div>
</div>`;
export default function Particle() {
const [jsx, setJsx] = useState("");
const [streaming, setStreaming] = useState(true);
useEffect(() => {
let i = 0;
const id = setInterval(() => {
i = Math.min(i + 18, final.length);
setJsx(final.slice(0, i));
if (i >= final.length) {
setStreaming(false);
clearInterval(id);
}
}, 60);
return () => clearInterval(id);
}, []);
return (
<div className="flex w-full max-w-2xl flex-col gap-3 p-4">
<ChatJsxPreview
bindings={{}}
components={{ Badge, Button }}
isStreaming={streaming}
jsx={jsx}
/>
<p className="text-muted-foreground text-xs">
{streaming
? "Streaming… auto-closes pending tags as they arrive."
: "Final JSX rendered."}
</p>
</div>
);
}
Installation
pnpm dlx shadcn@latest add @jenny/chat-jsx-preview
Использует react-jsx-parser — добавится в зависимости автоматически.
Usage
import { ChatJsxPreview } from "@/components/ui/chat-jsx-preview";
import { Button } from "@/components/ui/button";
<ChatJsxPreview
components={{ Button }}
isStreaming={isStreaming}
jsx={modelJsxOutput}
onError={(error) => console.warn("JSX preview error:", error)}
/>Streaming поведение
Когда isStreaming = true (по умолчанию), компонент автоматически добавляет недостающие закрывающие тэги до того, как модель их выдаст. Это позволяет рендерить частично-сформированный JSX без падений и моргания.
Безопасность
react-jsx-parser исполняет переданный JSX в React-окружении. Любой ввод от модели — это не доверенный контент. Жёстко контролируй то, что передаёшь:
components— белый список React-компонентов, доступных модели. Не добавляй сюда то, что может вызвать побочные эффекты при render.bindings— значения для выражений. Не пробрасывай функции с доступом к секретам / сети.
Также error boundary внутри ловит любые исключения рендера и показывает fallback вместо краха страницы.
On This Page