What is Hydration?
Hydration is the process of:- Server: Render React component to HTML string
- Client: Load React runtime and attach to existing DOM
- Result: Interactive React components
Enabling Hydration
Sethydrate: true in your UI config:
How It Works
Whenhydrate: true:
- The React component is rendered server-side with
renderToString() - The HTML includes hydration markers
- The React runtime is bundled with the widget
- On the client,
hydrateRoot()attaches to the existing DOM
Interactive React Components
With hydration, you can use full React features:src/widgets/counter.tsx
Using Hooks
With hydration enabled, React hooks work as expected:MCP Bridge Integration
Access MCP Bridge in hydrated components:Custom Hook for MCP Bridge
src/widgets/hooks/use-mcp-bridge.ts
Platform Considerations
Hydration requires:- JavaScript execution on the client
- React runtime to be loaded
OpenAI
Full support for hydration with React runtime loading from CDN.Claude
Limited support. Claude Artifacts have restricted JavaScript execution. Consider:- Keep interactions simple
- Use HTMX instead for basic interactivity
- Test thoroughly in Claude environment
Gemini
Basic JavaScript support. May have limitations on external script loading.Bundle Size
Hydration adds the React runtime to your widget. Consider:Minimizing Bundle Size
- Use smaller alternatives - Preact instead of React
- Code split - Only load what’s needed
- Lazy load - Import components dynamically
When to Use Hydration
Use hydration when:- Complex client-side state management
- Real-time updates (polling, WebSocket)
- Rich form interactions
- Animations and transitions
- Reusable interactive components
- Static data display only
- Simple interactions (use HTMX)
- Claude/Gemini is primary target
- Bundle size is a concern
Alternative: HTMX
For simpler interactions, consider HTMX instead:Best Practices
- Check platform support - Not all platforms handle hydration well
- Minimize bundle size - Only include what you need
- Handle SSR/CSR differences - Avoid hydration mismatches
- Use progressive enhancement - Work without JS first
- Test across platforms - Verify behavior everywhere

