Skip to main content
Reatom provides comprehensive developer tools for debugging and inspecting your application state, actions, and dependencies. This guide covers the built-in logger and the DevTools UI.

Quick Start

Install DevTools

Basic Logger Setup

The simplest way to debug Reatom apps is using the built-in connectLogger:
This logs all state changes, action calls, and dependencies to your browser console.
Add this early in your application entry point, before any atoms are created or accessed.

Using the Logger

Basic Logging

Filtering Logs

Filter which atoms and actions appear in logs:

Excluding Private State

By convention, atoms starting with _ are private:
The default filter pattern in DevTools excludes names starting with _ or ._ to hide internal implementation details.

Log Levels and Formatting

The logger automatically traces the call stack and shows which action triggered the log.

State Change Logging

Log only when specific state changes:

DevTools UI

The @reatom/devtools package provides a visual interface for inspecting your Reatom state graph.

Installation and Setup

1

Install the package

2

Create and mount DevTools

3

Access the UI

The DevTools UI automatically appears in the bottom-right corner of your browser window (in development mode).

DevTools Configuration

DevTools API

The DevTools instance provides programmatic control:

DevTools Features

Logs View

The main logs panel shows:
  • Action calls with parameters
  • State changes with before/after values
  • Dependency chains showing what triggered what
  • Timestamps for performance analysis
  • Stack traces for debugging

Filter Actions

Create custom filters to focus on specific parts of your state:
  • Filter mode: Show only matching logs
  • Hide mode: Hide matching logs
  • Exclude mode: Remove from collection entirely (performance optimization)
  • Highlight mode: Color-code matching logs
Filters support both regex patterns and value search (searches stringified payloads).
Save frequently-used filters to quickly switch between different debugging contexts.

Log Controls

  • Clear logs: Remove all collected logs
  • Clear lines: Remove cause chain highlight lines
  • Recording: Pause/resume log collection
  • Preview: Toggle inline payload preview
  • Time: Toggle timestamp display
  • Snap: Create snapshot of current visible logs
  • Size: Adjust log collection limit

States View

Hierarchical tree view of all atoms in your application:
  • Organized by name separator (e.g., user.profile.name)
  • Excludes actions and private atoms by default
  • Real-time updates via proto.updateHooks
  • “Reload” button to force snapshot refresh
  • “Log” button to output state to console
The states view uses structuredClone when possible, falling back to live data references for non-cloneable objects.

Inspector

Click any state value to open the inspector panel:

Inspector Actions

  • Edit: Open JSON form to modify state (uses JSON.parse)
  • History: View diff between current and previous states (max 10 entries)
  • Log to console: Output current value to browser console
  • Copy JSON: Copy stringified value to clipboard
  • Download: Save value as JSON file
  • Convert to plain JSON: Remove Reatom atoms from data structure
State edits from the inspector go through a special update action. They will trigger all normal subscribers and effects.

Cause Chain Tracing

Click any log entry to highlight its cause chain:
  • Visual lines connect causes to effects
  • Shows dependencies that triggered updates
  • Helps understand why state changed
  • Traces through async boundaries

Time Travel Debugging

Use snapshots to capture and restore state:

Integration with Browser DevTools

Chrome/Edge DevTools Extension

Reatom integrates with browser DevTools through the @reatom/devtools package:
  1. The DevTools UI renders in a Shadow DOM container with isolated styles
  2. Uses ObservableHQ Inspector for rich data visualization
  3. Includes jsondiffpatch for visual state diffs

Console Integration

Persistence

DevTools settings are saved to localStorage:
  • Filter configurations (with version key)
  • View preferences (logs vs. states)
  • Panel visibility
  • Size settings
Settings use Zod for validation to handle version migrations safely.

Performance Considerations

Production Builds

Always guard DevTools and logging with environment checks:
This ensures DevTools code is tree-shaken from production bundles.

Log Collection Limits

Use the initSize option to prevent memory issues:
The DevTools automatically trim old logs when the limit is reached.

Exclude Filters

Use “exclude” mode filters for high-frequency atoms:

Debugging Recipes

Find Why State Changed

1

Open DevTools and find the atom

Look in the Logs view for the unexpected state change.
2

Click the log entry

This highlights the cause chain showing all dependencies that triggered the update.
3

Follow the chain backwards

Trace from effect back to cause to find the root trigger.

Debug Async Operations

Enable stack traces to see async call chains:
The logger shows the complete async execution path.

Inspect Complex State

Use the inspector’s “Convert to plain JSON” feature to remove Reatom wrappers:
  1. Click the state value in DevTools
  2. Click “Convert to plain JSON”
  3. Copy or download the plain object

Track State Over Time

Use history diffs to see how state evolved:
  1. Click a state value in the inspector
  2. Click “History” button
  3. Review visual diffs showing changes over time
History tracking uses reference equality. In-place mutations won’t appear in diffs - always create new objects/arrays.

Best Practices

  1. Name everything - Give all atoms and actions descriptive names for better logs
  2. Use namespacing - Structure names like user.profile.email for hierarchical views
  3. Filter aggressively - Hide internal implementation details with filters
  4. Check logs regularly - Catch unexpected updates early in development
  5. Use LOG liberally - Add logging to complex operations while developing
  6. Guard production - Always wrap DevTools in environment checks

Troubleshooting

DevTools Not Appearing

Check that:
  • DevTools is created before atoms are accessed
  • initVisibility is true
  • You’re in development mode
  • No console errors from DevTools initialization

Missing Logs

Ensure:
  • connectLogger() is called before atom updates
  • Your filters aren’t hiding the logs
  • Recording is enabled (check the “recording” toggle)

Performance Issues

If DevTools slows your app:
  • Reduce initSize limit
  • Add exclude filters for high-frequency atoms
  • Disable recording when not actively debugging
  • Close the DevTools panel (it still collects but renders less)

Further Reading