Skip to content

Add Live Component Debugger with real-time event streaming#66

Merged
MarcosBrendonDePaula merged 15 commits intomainfrom
claude/live-component-debugger-s8ESd
Feb 22, 2026
Merged

Add Live Component Debugger with real-time event streaming#66
MarcosBrendonDePaula merged 15 commits intomainfrom
claude/live-component-debugger-s8ESd

Conversation

@MarcosBrendonDePaula
Copy link
Copy Markdown
Collaborator

Summary

Adds a comprehensive debugging system for Live Components that provides real-time visibility into component lifecycle, state changes, actions, and room events. Includes server-side event capture, WebSocket streaming, and client-side UI components for inspection.

Key Changes

  • Server-side debugger (core/server/live/LiveDebugger.ts): Event bus that captures and tracks:

    • Component mount/unmount/rehydrate lifecycle
    • State changes with delta tracking
    • Action calls, results, and errors with duration metrics
    • Room join/leave/emit events
    • WebSocket connections/disconnections
    • Errors with context
    • Maintains circular buffer of 500 events and component snapshots
  • Client hook (core/client/hooks/useLiveDebugger.ts): React hook that:

    • Connects to debug WebSocket endpoint
    • Streams real-time events and component snapshots
    • Provides filtering, pause/resume, and event clearing controls
    • Tracks component state, action counts, error counts, and room memberships
  • UI Components:

    • core/client/components/LiveDebugger.tsx: Compact floating panel with tabs for events and state inspection
    • app/client/src/live/LiveDebuggerPanel.tsx: Full-featured debugger panel with detailed event timeline, component list, state inspector, and advanced filtering
  • WebSocket routes (core/server/live/websocket-plugin.ts):

    • /api/live/debug/ws: WebSocket endpoint for streaming debug events
    • /api/live/debug/snapshot: REST endpoint for current component state
    • /api/live/debug/events: REST endpoint for event history with filtering
  • Integration: Debugger is auto-enabled in development mode and injected into LiveComponent class via ComponentRegistry to track all instrumented events

Notable Implementation Details

  • Events are sanitized to prevent large state objects from blogging the debug stream (50KB limit)
  • Component snapshots include developer-defined debugLabel for easier identification
  • Debug clients receive welcome message with current snapshot plus last 100 events on connection
  • Debugger is disabled in production unless DEBUG_LIVE=true environment variable is set
  • Circular event buffer prevents unbounded memory growth
  • Auto-reconnection with 3-second backoff for debug WebSocket clients

https://claude.ai/code/session_01UjPuBmfmnczYxAXNVTYdKW

claude and others added 15 commits February 22, 2026 01:00
Adds a visual debugger that connects via WebSocket to monitor all Live
Component activity in real-time. Captures state changes, action calls,
room events, connections, and errors — all organized per component.

Server-side:
- LiveDebugger.ts: event bus singleton with circular buffer, component
  snapshots, and debug client management (auto-enabled in development)
- Debug WebSocket endpoint at /api/live/debug/ws for real-time streaming
- HTTP endpoints for snapshot, events, component state, and toggle
- Instrumented LiveComponent (setState, proxy, executeAction, rooms)
  and ComponentRegistry (mount, unmount, connections) with debug events

Client-side:
- useLiveDebugger hook: connects to debug WS, manages event stream,
  component tracking, filtering, pause/resume
- LiveDebuggerPanel: full-page UI with component sidebar, event timeline
  with expandable JSON, state inspector, type filtering, and search
- Accessible at /debugger route

https://claude.ai/code/session_01UjPuBmfmnczYxAXNVTYdKW
The LiveDebugger module uses process.env which doesn't exist in the
browser. Instead of importing it directly in types.ts (which is shared
between server and client), use an injectable pattern: define a
lightweight interface in types.ts and inject the real instance from
ComponentRegistry at server startup.

https://claude.ai/code/session_01UjPuBmfmnczYxAXNVTYdKW
Replace the full-page /debugger route with an in-page floating overlay
component that shows debug data directly on the page being developed.

LiveDebugger overlay:
- Collapsible bar at the bottom of the screen (click to expand)
- Component sidebar with live stats (state changes, actions, errors)
- Event feed with expandable JSON, color-coded by type
- State inspector tab showing current component state
- Pause/resume, clear, auto-scroll controls

debugLabel option:
- Developers can set a custom label for each component instance:
    Live.use(LiveCounter, { debugLabel: 'Header Counter' })
- The label flows from client -> mount payload -> server -> debugger
- Shown prominently in the debugger instead of the UUID component ID
- Component class name shown as subtitle when label is set

https://claude.ai/code/session_01UjPuBmfmnczYxAXNVTYdKW
The $field() helper internally calls the setValue action to sync form
field values to the server, but LiveForm didn't include it in its
publicActions whitelist, causing "Action 'setValue' is not callable".

https://claude.ai/code/session_01UjPuBmfmnczYxAXNVTYdKW
Major UX improvements:
- Floating draggable window instead of fixed bottom bar that blocked clicks
- Resizable from bottom-right corner
- Keyboard shortcut Ctrl+Shift+D to toggle open/close
- Event type filter chips grouped by category (Lifecycle, State, Actions,
  Rooms, WS, Errors) with live counts
- Search bar to filter events by content
- Auto-scroll with manual scroll detection and "scroll to bottom" button
- Minimized state is a small badge showing component count (not a full bar)
- Badge shows error indicator when errors are present

https://claude.ai/code/session_01UjPuBmfmnczYxAXNVTYdKW
Clicking a component in the sidebar no longer forces the tab back to
'events' — it stays on whichever tab (events/state) was already active.

https://claude.ai/code/session_01UjPuBmfmnczYxAXNVTYdKW
New "Rooms" tab shows:
- Active rooms with member count
- Components in each room with stats
- Recent room activity feed (JOIN, LEAVE, EMIT events)

Rooms are derived from component snapshots in real-time.

https://claude.ai/code/session_01UjPuBmfmnczYxAXNVTYdKW
The old viewer truncated nested data at depth 2 (showing {...4} for
objects), making it impossible to inspect deep structures like chat
messages or room state.

New tree viewer:
- Click arrows to expand/collapse any object or array
- Top-level state auto-expands, nested nodes start collapsed
- Inline preview of collapsed nodes (e.g. { id: "tech", name: "..." })
- Shows item/key counts when expanded
- No depth limit - drill as deep as needed
- Strings display up to 120 chars before truncating

https://claude.ai/code/session_01UjPuBmfmnczYxAXNVTYdKW
Clicking to collapse/expand JSON nodes inside an event's detail area
was bubbling up and toggling the parent event row closed.

https://claude.ai/code/session_01UjPuBmfmnczYxAXNVTYdKW
Server side:
- registerDebugClient() now checks _enabled flag
- If disabled, sends DEBUG_DISABLED message and closes the WebSocket
- Welcome message includes enabled status

Client side:
- Hook tracks serverDisabled state
- Stops auto-reconnect loop when server reports disabled
- LiveDebugger renders nothing (null) when server is disabled
- New force prop to override and show debugger anyway

Flow:
- Development: auto-enabled, debugger works normally
- Production: server rejects debug WS, client renders nothing,
  no reconnect loop, zero resource usage
- Production + DEBUG_LIVE=true: server accepts, debugger works

https://claude.ai/code/session_01UjPuBmfmnczYxAXNVTYdKW
DEBUG_LIVE now takes priority over NODE_ENV when explicitly set:
- DEBUG_LIVE=true  -> enabled (any environment)
- DEBUG_LIVE=false -> disabled (any environment)
- Not set          -> enabled in development, disabled otherwise

https://claude.ai/code/session_01UjPuBmfmnczYxAXNVTYdKW
…aw env vars

LiveDebugger now reads `debugLive` from `appRuntimeConfig` (config/system/runtime.config.ts)
instead of parsing process.env directly. The config defaults to true in development, false
otherwise, and can be overridden via the DEBUG_LIVE env var.

https://claude.ai/code/session_01UjPuBmfmnczYxAXNVTYdKW
…e, word wrap

Adds a configuration panel to both the floating debugger widget (new Settings tab
with gear icon) and the full-page debugger panel (collapsible settings drawer).

Settings include:
- Font size (XS/SM/MD/LG) for adjusting text readability
- Max events buffer size (100/300/500/1000)
- Show/hide timestamps toggle
- Compact mode for denser event display
- Word wrap toggle for long data values
- Reset to defaults button

All settings persist to localStorage and are shared between both debugger views.

https://claude.ai/code/session_01UjPuBmfmnczYxAXNVTYdKW
@MarcosBrendonDePaula MarcosBrendonDePaula merged commit e0e770c into main Feb 22, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants