You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Next.js app router example
* Update READMEs
* Avoid building examples on unsupported nodes
* Let ci continue building with the other node versions
* Use the latest rollbar version 2.26.4
---------
Co-authored-by: Matthew LaForest <[email protected]>
We suggest you create a single instance for use server side, to be certain there are not more than one, and a config to use in your client side components. React Server Components limit you to passing simple objects as props from Server Components to Client Components. The config object can be used by the Rollbar Provider to construct your Rollbar instance.
167
+
168
+
There's a fully functional [example](./examples/nextjs-approuter) that showcases the many ways in which you can integrate Rollbar into your modern web-app leveraging React Server Components and the Next.js App Router.
169
+
128
170
## Components
129
171
130
172
The following components are available as named imports from `@rollbar/react`.
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2
+
3
+
## Getting Started
4
+
5
+
First, run the development server:
6
+
7
+
```bash
8
+
npm run dev
9
+
# or
10
+
yarn dev
11
+
# or
12
+
pnpm dev
13
+
# or
14
+
bun dev
15
+
```
16
+
17
+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18
+
19
+
## Using Rollbar with the Next.js App Router
20
+
21
+
The first step to using Rollbar with the Next.js App Router is to configure your Rollbar instance.
We suggest you create a single instance for use server side, to be certain there are not more than one, and a config to use in your client side components. React Server Components limit you to passing simple objects as props from Server Components to Client Components. The config object can be used by the Rollbar Provider to construct your Rollbar instance.
45
+
46
+
### Configuring the Rollbar Provider
47
+
48
+
To be able to use the hooks consistently through your application. It is easiest if you configure your Rollbar Provider within your root layout.
49
+
50
+
**_Note:_** The Rollbar Provider uses a React Context. This context, like hooks are only available for use in your client components.
51
+
52
+
### Configuring the global-error handler
53
+
54
+
To be certain that you are catching all errors within your application, you will want to [configure a `global-error.js/tsx`](./src/app/global-error.tsx). This handler will catch errors, including from your root layout and relay then to Rollbar.
55
+
56
+
### Using the Next.js route error handler (Recommended)
57
+
58
+
Next.js provides an [error handler]() this handler will automatically wrap your router, at the desired level, within an [Error Boundary](). It is recommended to [use your Rollbar instance within this error handler](./src/app//next_error_handler/error.tsx) to report errors to Rollbar.
59
+
60
+
### Using the Rollbar ErrorBoundary
61
+
62
+
The `<ErrorBoundary>` component provided by this library [may still be used](./src/app/rollbar_error_boundary/page.tsx) if you would prefer that over the built in Next.js error handler
63
+
64
+
#### Special note on Error boundaries
65
+
66
+
The ErrorBoundary class is not perfect at catching and stopping the propagation of all errors. Be aware, that if you turn on `captureUncaught` or `captureUnhandledRejections` in your Rollbar config you may receive doubled occurrences.
0 commit comments