Connect a React application to Bugsink

When a component fails while React is rendering it, an error boundary can show fallback UI instead of leaving that part of the page broken. Bugsink gives you the component error and the original JSX source behind the production bundle.

This guide adds the React SDK and its error boundary to a Vite application, uploads source maps, and triggers a deliberate render error. To follow along, create a Bugsink project and copy its DSN. The quickstart guide shows where to find it.

Install the React SDK

Install the open-source Sentry SDK for React. Bugsink accepts the Sentry event protocol, so the SDK can send component errors directly to your Bugsink project:

npm install @sentry/react

Initialize the SDK and add an error boundary

Initialize the SDK before rendering the component tree. Vite exposes variables prefixed with VITE_ to browser code, so this example reads the project DSN from VITE_SENTRY_DSN. A DSN identifies the project and is safe to include in the browser bundle; it is not an administrative token.

Wrap the part of the tree you want to protect in Sentry.ErrorBoundary. The fallback is ordinary React UI which replaces the boundary’s children after a render error:

import * as Sentry from "@sentry/react";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";

import App from "./App.jsx";


Sentry.init({
  dsn: import.meta.env.VITE_SENTRY_DSN,
});

createRoot(document.querySelector("#root")).render(
  <StrictMode>
    <Sentry.ErrorBoundary fallback={<p>That product could not be displayed.</p>}>
      <App />
    </Sentry.ErrorBoundary>
  </StrictMode>,
);

Build with source maps

A production React build contains bundled, minified JavaScript rather than the JSX files you edit. Configure Vite to emit a source map so Bugsink can translate the captured production frame back to App.jsx:

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";


export default defineConfig({
  plugins: [react()],
  build: {
    sourcemap: true,
  },
});

Build with the project DSN:

VITE_SENTRY_DSN=https://key@bugsink.example/1 npm run build

Upload the source maps to Bugsink

sentry-cli adds matching debug IDs to the bundle and map, then uploads both to Bugsink. Create a project-bound token with the debug-files:upload capability and keep it in the build environment, never in browser code.

npx --yes @sentry/cli sourcemaps inject ./dist

Upload the injected build, replacing the URL and project slug with your own. Bugsink has no organization object, so --org is only a compatibility value:

SENTRY_AUTH_TOKEN=your-project-token \
npx --yes @sentry/cli \
  --url https://bugsink.example \
  sourcemaps --org bugsink --project your-project-slug upload ./dist

Upload maps for every production build before it can report errors. You may remove .map files from dist after a successful upload if your web server should not publish them.

Trigger a component render error

For this setup check, the Product component deliberately throws when the selected SKU does not exist:

function Product({ sku }) {
  const product = products[sku];
  if (!product) {
    throw new Error("React product render failed [react-error-boundary]");
  }
  return <p>{product.name}: {product.stock} in stock</p>;
}

Serve the production build, open the page, and click Display a missing product:

npm run preview

The boundary reports the error and replaces the inventory tree with That product could not be displayed.

See the component error in Bugsink

Open the new issue in Bugsink. The React event is marked as handled by the error boundary, includes the React version, and points to the original JSX line which failed.

Bugsink preview

That’s it: your React component boundary is connected. Remove the deliberate error. Future render failures inside the boundary will show its fallback and reach Bugsink with their component and JavaScript stacks.

An error boundary catches render and lifecycle errors in its descendants, not errors in the boundary itself. Put boundaries where fallback UI can preserve a useful remainder of the page—for example around a route, checkout panel, or independently loaded widget rather than automatically wrapping every component.

Event-handler and asynchronous errors do not activate React’s fallback UI. They may still reach Bugsink through the browser SDK’s global error handling; catch and report them explicitly when your application handles them itself.