Overview
Level 3: Advanced · Module 8: Generative UI · 18 min read · Core Track
Why this matters
For years, AI chat interfaces have been restricted to markdown text walls: bold bullet points, numbered lists, and fenced code blocks. If a user asks for flight options, the assistant replies with 400 words of plain text. Generative UI (GenUI) shifts this paradigm: instead of responding with static text, the model dynamically returns interactive, fully functional React components—interactive flight picker cards, live stock charts, editable forms, calendar booking widgets, and payment checkout flows. However, when applied blindly, Generative UI can be a disastrous anti-pattern: causing jarring layout shifts, rendering unverified broken HTML, exposing security injection vectors, or frustrating users who just wanted a quick factual answer.
Learning objectives
- Define Generative UI and contrast it with traditional markdown text rendering.
- Identify high-value GenUI use cases (interactive selectors, complex data visualizers).
- Recognize the 4 anti-patterns where Generative UI ruins user experience.
- Compare server-rendered Generative UI (RSC streaming) vs client-rendered schema-driven UI.
- Defend component registry security boundaries against arbitrary code injection.
Generative UI vs Traditional Markdown Text
Traditional Text Wall:
"Here are three flights:
1. United Airlines flight 412 departing at 8:30 AM for $389.
2. Delta flight 908 departing at 11:15 AM for $410.
3. American Airlines flight 204 departing at 2:45 PM for $365.
Which would you like to book?"
➔ Low engagement, high cognitive load, manual re-typing required.
Generative UI:
┌─────────────────────────────────────────────────────────────────────────────┐
│ ✈️ United Airlines (UA-412) $389 │
│ SFO 08:30 AM ───────── Non-stop (5h 40m) ─────────► JFK 05:10 PM │
│ [ Select Flight & Reserve Seat ] │
└─────────────────────────────────────────────────────────────────────────────┘
➔ High engagement, verified pricing, single-click transactional action.graph TD
UserQuery["User: 'Show me my team's sprint burndown'"] --> LLM["LLM Inference Turn"]
LLM --> Decision{"What is the optimal response format?"}
Decision -->|Unstructured Prose| Text["Markdown Text Stream"]
Decision -->|Interactive Data / Selection| GenUI["Generative UI Component"]
GenUI --> Registry["Verified ComponentRegistry"]
Registry --> ClientComp["<SprintBurndownChart data={...} />"]
ClientComp --> LiveDOM["Interactive SVG Chart with Hover Tooltips in Chat"]The 4 Major Anti-Patterns: When NOT to Use Generative UI
- The "Everything is a Widget" Trap:
- Anti-Pattern: Rendering a custom styled card for a simple binary question like "Is the office open today?".
- Fix: If the answer is a single factual sentence, return plain text. Reserve Generative UI for choices, actions, or high-dimensional data.
- Arbitrary JSX / HTML Execution (Catastrophic XSS):
- Anti-Pattern: Asking the model to emit raw HTML or JSX strings (
dangerouslySetInnerHTML) and rendering it in the DOM. - Fix: Never evaluate arbitrary model-generated JSX strings. The model must only output structured JSON props that feed into hardcoded, compile-time verified React components.
- Anti-Pattern: Asking the model to emit raw HTML or JSX strings (
- Layout Shift Thrashing:
- Anti-Pattern: Rendering components that pop into existence mid-stream, jumping the scroll position by 400px and breaking user reading focus.
- Fix: Use fixed-height skeletons and optimistic placeholders while tool payloads stream in.
- Broken State Synchronization:
- Anti-Pattern: A generated form modifies data, but the surrounding chat history has no record of the user's interaction.
- Fix: When a user interacts with a Generative UI component (e.g. clicking "Book"), emit an explicit event back into the conversation state machine.
The Two Technical Implementation Paths
| Architecture | Server-Driven (RSC Payload Streaming) | Client-Driven (Schema-to-Component Registry) |
|---|---|---|
| How it works | Server Actions stream serialized React Server Component nodes directly | Model outputs JSON schema; client maps to pre-compiled React component |
| Pioneered by | Vercel AI SDK (createStreamableUI, RSC) | OpenAI Function Calling + Client Component Registry |
| Client Bundle Size | Smaller (components stay on server) | Slightly larger (all candidate components bundled on client) |
| State & Interactivity | Requires "use client" leaf boundaries | Full native client state, hooks, and local event handlers |
| Offline / Portability | Tied exclusively to Next.js App Router | Portable to any framework (Vite, React Native, Remix) |
| Recommended Verdict | Next.js full-stack internal dashboards | General enterprise SaaS standard |
Interview Angle: How to Answer in System Design
- Question: "How do you implement Generative UI securely without exposing your application to Cross-Site Scripting (XSS) or arbitrary code execution?"
- Target Answer:
"We enforce a strict separation between data generation and component rendering.
Under no circumstances do we allow the LLM to output raw JSX, HTML, or JavaScript strings to be evaluated by
eval()ordangerouslySetInnerHTML.Instead, the model is restricted to standard tool calling: it outputs a typed JSON payload specifying a component identifier (e.g.
FlightCard) and structured properties.On the client, a static, allowlisted
ComponentRegistrymaps that identifier to a pre-compiled, audited React component. The props are validated through Zod.safeParse(). If props fail validation or the component is unrecognized, we trigger a defensive fallback ladder down to a read-only JSON viewer."
Quick Check
- Why is rendering raw HTML/JSX emitted by an LLM a severe security vulnerability?
- Name two scenarios where Generative UI is a user experience anti-pattern.
- What is the difference between server-streamed RSC Generative UI and schema-driven client Generative UI?