Skip to main content

Remix and React Router

Beta

This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas.

@bugsee/remix is the adapter for Remix and for React Router v7 and v8 in framework mode. It reports server errors through handleError in entry.server, and captures the browser through entry.client. It is a single install: it bundles the browser and Node.js SDKs and re-exports the React adapter from @bugsee/remix/client.

Requirements​

  • Remix, or React Router v7 or v8 in framework mode. The onError prop used below needs React Router 7.11 or newer; earlier 7.x releases expose it as unstable_onError.
  • Node.js 18 or newer for server code.
  • react 18 or newer (optional peer dependency).
  • An app token. Create a JavaScript application in Bugsee and choose Remix as its target; see Create your app.

Install​

npm install @bugsee/remix

Set up​

Server​

Launch Bugsee on the server and export handleError so unhandled server errors are reported.

app/entry.server.tsx
import { registerServer } from '@bugsee/remix/server';

registerServer(process.env.BUGSEE_TOKEN!);

export { handleError } from '@bugsee/remix';

registerServer returns the started client directly.

Client​

Launch the browser SDK at the top of entry.client and pass bugseeOnError to the router, so React errors are reported with their component stack.

app/entry.client.tsx
import { registerClient, bugseeOnError } from '@bugsee/remix/client';

registerClient(import.meta.env.VITE_BUGSEE_TOKEN);

hydrateRoot(document, <HydratedRouter onError={bugseeOnError} />);

registerClient returns a Promise of the client. An application token is not a secret, so it is fine in a VITE_ variable.

Remix v2​

Remix v2 has no onError prop. Call captureRemixErrorBoundaryError from your root ErrorBoundary. Expected control flow, such as 404s, redirects and thrown responses, is skipped.

app/root.tsx
import { captureRemixErrorBoundaryError } from '@bugsee/remix/client';
import { useRouteError } from '@remix-run/react';

export function ErrorBoundary() {
captureRemixErrorBoundaryError(useRouteError());
return <RootError />;
}

Entry points​

EntryExports
@bugsee/remixhandleError, createHandleError(options?), getBugseeTraceMetaTags(options?)
@bugsee/remix/serverregisterServer, getBugseeMetaTagTransformer, the shared client exports and relaunch
@bugsee/remix/clientregisterClient, bugseeOnError, captureRemixErrorBoundaryError, plus the React adapter

getBugseeTraceMetaTags() renders a <meta name="traceparent"> tag for the active server request. The browser client reads it on page load, so the server request and the initial page session become one trace.

Options​

registerServer(appToken, options) and registerClient(appToken, options) accept the SDK launch options. The most relevant:

WhereOptionDefaultDescription
ServerinstrumentIncomingRequeststrueInstrument incoming requests.
ServercaptureLocalVariablesfalseCapture local variables on errors.
ServerdetectHangstrueEvent-loop hang detection.
ClientcaptureLogs, captureNetworktrueConsole and network capture.
ClientmaxRecordingTime60Seconds of recording to keep.
ClientreplaytrueSession replay. Pass false to turn it off.

See Browser and Node.js for the full lists.

Notes​

  • Source maps. The Vite plugin uploads them as part of the build. See Bundler plugins.
  • Backend context. Each server request gets a context so logs and errors tie to it. See Backend.

Verify​

Throw from a loader:

app/routes/test.tsx
export function loader() {
throw new Error('Bugsee test error');
}

Open /test. The error shows up in the Bugsee dashboard.

Found an issue, typo, or wrong statement on this page? Report it now →