Skip to content

DevTools

StateMesh provides an in-app DevTools dock for development and QA. It includes tabs for state, actions, resources, mutations, forms, URL state, components, profiler, diagnostics, and raw events.

Quick Setup

tsx
import { StateMeshDevtools } from "statemesh-core/devtools";

function App() {
  return (
    <StateMeshProvider mesh={mesh}>
      <AppContent />
      <StateMeshDevtools
        mesh={mesh}
        mask={["auth.token", "user.email"]}
        previewBytes={2000}
        defaultView="overview"
        theme="light"
      />
    </StateMeshProvider>
  );
}

Props

PropTypeDefaultDescription
meshMeshRequiredThe mesh instance
maskstring[][]Paths to mask in the UI
previewBytesnumber2000Max bytes for value previews
defaultViewDevtoolsView"overview"Initial tab
theme"light" | "dark""light"UI theme
hiddenbooleanfalseStart hidden
limitnumber200Max events in timeline
logActiveMessagebooleantrueLog activation message to console

Tabs

TabShows
OverviewHealth counts, active resources, pending transactions
StateCurrent state snapshot
ActionsAction and transaction timeline
ResourcesCache entries with refetch/invalidate controls
MutationsMutation status and offline queue
FormsValues, errors, dirty, touched, steps
URLCurrent URL state
ComponentsTracked React components and their StateMesh usage
ProfilerPerformance samples for slow operations
DoctorRuntime diagnostics
EventsRaw event timeline with search, filters, export

Component Tracking

Wrap UI areas with MeshComponent to track StateMesh usage:

tsx
import { MeshComponent } from "statemesh-core";

function ProductScreen() {
  return (
    <MeshComponent name="ProductScreen">
      <ProductFilters />
      <ProductList />
    </MeshComponent>
  );
}

The Components tab shows tracked component names, render counts, and captured StateMesh usages.

Programmatic Access

ts
// Get a safe snapshot
const snapshot = mesh.getDevtoolsSnapshot({
  mask: ["auth.token"],
  previewBytes: 4000
});

// Subscribe to changes
const unsubscribe = mesh.subscribeDevtools(() => {
  console.log(mesh.getDevtoolsSnapshot().summary);
});

Profiler

ts
const slowOps = mesh.getProfilerSamples({
  slowOnly: true,
  minDuration: 16
});

mesh.subscribeProfiler(() => {
  console.table(mesh.getProfilerSamples({ limit: 10 }));
});

Doctor Diagnostics

ts
const report = mesh.doctor({
  stateSizeWarningBytes: 250_000,
  queuedMutationAgeWarning: "5m",
  staleResourceWarning: "5m",
  slowOperationWarningMs: 16
});

Doctor reports: large serialized state, resources without tags, resource errors, stale cache, stuck mutations, unresolved form errors, slow operations.

Logger Plugin

ts
import { loggerPlugin } from "statemesh-core/devtools";

mesh.use(loggerPlugin({
  enabled: process.env.NODE_ENV === "development",
  mask: ["user.email", "auth.token"]
}));

Important Notes

TIP

DevTools is tree-shakeable. Import from statemesh-core/devtools — it's not included in the main bundle.

WARNING

mask is applied before rendering state, forms, URL, resources, mutations, and exports. Sensitive paths are never displayed.

Next Steps

Released under the MIT License.