Skip to content

Commit 01b7601

Browse files
docs(js): Review and update TanStack Start React quick start guide (#14879)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR Reviewed the existing TanStack Start React quick start guide and made some updates: - improved structures by adding subheadings - rewrote some explanations to be more concise and in line with similar content in other QS guides - updated verification code snippets (tested with the latest version of the framework) Closes: #14878 ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Rewrites and restructures the TanStack Start React quick start with clearer client/server setup, SSR and server instrumentation, updated tracing example, and improved verification and links. > > - **Docs — TanStack Start React guide (`index.mdx`)**: > - **Restructure**: Clearer intro and step-based flow; added subheadings and optional sections. > - **Client/Server Setup**: Separate client and server init; clarified config and options. > - **Performance/SSR**: Added `wrapCreateRootRouteWithSentry` and `wrapStreamHandlerWithSentry`; grouped under performance option. > - **Server Functions**: Added global middleware via `sentryGlobalServerMiddlewareHandler`. > - **Error Handling**: Guidance for error boundaries via `withErrorBoundary` and capturing `errorComponent` errors with `captureException`; note on automatic client capture. > - **Tracing Example**: Replaced API route with server route `src/routes/sentry-example.ts` (`/sentry-example`); updated fetch path and example code. > - **Verification/Extras**: Added tunneling section; refined verification steps; expanded Next Steps with product features and troubleshooting links. > - **Docs — Config (`config.yml`)**: Updated description to a more comprehensive summary. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 2ba052c. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 779e82a commit 01b7601

File tree

2 files changed

+55
-29
lines changed

2 files changed

+55
-29
lines changed

docs/platforms/javascript/guides/tanstackstart-react/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
title: TanStack Start React
2-
description: Learn how to set up TanStack Start React with Sentry.
2+
description: Learn how to set up and configure Sentry in your TanStack Start React application, capturing your first errors, and viewing them in Sentry.
33
sdk: sentry.javascript.tanstackstart-react
44
categories:
55
- javascript

docs/platforms/javascript/guides/tanstackstart-react/index.mdx

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
---
22
title: TanStack Start React
3-
description: "Learn how to set up and configure Sentry in your TanStack Start React application, capturing your first errors, and viewing them in Sentry."
43
---
54

65
<Alert>
76

87
This SDK is currently in **ALPHA**. Alpha features are still in progress, may have bugs and might include breaking changes.
98
Please reach out on [GitHub](https://github.com/getsentry/sentry-javascript/issues/new/choose) if you have any feedback or concerns.
10-
This SDK is for [TanStack Start (React)](https://tanstack.com/start/latest/docs/framework/react/overview), for
11-
using [TanStack Router (React)](https://tanstack.com/router/latest/docs/framework/react/overview) see our React docs for
12-
[TanStack Router](/platforms/javascript/guides/react/features/tanstack-router).
139

1410
</Alert>
1511

12+
This guide walks you through setting up Sentry in a [TanStack Start (React)](https://tanstack.com/start/latest/docs/framework/react/overview) app.
13+
For [TanStack Router (React)](https://tanstack.com/router/latest/docs/framework/react/overview), see our [React TanStack Router guide](/platforms/javascript/guides/react/features/tanstack-router).
14+
1615
<PlatformContent includePath="getting-started-prerequisites" />
1716

1817
## Step 1: Install
@@ -31,6 +30,8 @@ Choose the features you want to configure, and this guide will show you how:
3130

3231
<PlatformContent includePath="getting-started-features-expandable" />
3332

33+
### Install the Sentry SDK
34+
3435
Run the command for your preferred package manager to add the SDK package to your application:
3536

3637
```bash {tabTitle:npm}
@@ -47,7 +48,9 @@ pnpm add @sentry/tanstackstart-react
4748

4849
## Step 2: Configure
4950

50-
Add the following initialization code to your `src/client.tsx` file to initialize Sentry on the client:
51+
### Configure Client-Side Sentry
52+
53+
Create a `src/client.tsx` file (if you don't already have one) and initialize Sentry:
5154

5255
```tsx {filename:src/client.tsx}
5356
import { hydrateRoot } from "react-dom/client";
@@ -105,7 +108,9 @@ Sentry.init({
105108
hydrateRoot(document, <StartClient router={router} />);
106109
```
107110

108-
Add the following initialization code anywhere in your `src/server.tsx` file to initialize Sentry on the server:
111+
### Configure Server-Side Sentry
112+
113+
Next, import and initialize Sentry in `src/server.tsx`:
109114

110115
```tsx {filename:src/server.tsx}
111116
import * as Sentry from "@sentry/tanstackstart-react";
@@ -133,7 +138,11 @@ Sentry.init({
133138
});
134139
```
135140

136-
Wrap TanStack Start's `createRootRoute` function using `wrapCreateRootRouteWithSentry` to apply tracing to Server-Side Rendering (SSR):
141+
<OnboardingOption optionId="performance">
142+
143+
### Apply Tracing to SSR
144+
145+
Wrap `createRootRoute` with `wrapCreateRootRouteWithSentry` in `src/routes/__root.tsx` to apply tracing to Server-Side Rendering (SSR):
137146

138147
```tsx {filename:src/routes/__root.tsx} {3,6}
139148
import type { ReactNode } from "react";
@@ -146,7 +155,13 @@ export const Route = wrapCreateRootRouteWithSentry(createRootRoute)({
146155
});
147156
```
148157

149-
Wrap TanStack Start's `defaultStreamHandler` function using `wrapStreamHandlerWithSentry` to instrument requests to your server:
158+
</OnboardingOption>
159+
160+
## Step 3: Capture TanStack Start React Errors
161+
162+
### Instrument Server Requests
163+
164+
Wrap the default stream handler with `wrapStreamHandlerWithSentry` in `src/server.tsx` to instrument requests to your server:
150165

151166
```tsx {filename:src/server.tsx} {12}
152167
import {
@@ -163,11 +178,13 @@ export default createStartHandler({
163178
})(Sentry.wrapStreamHandlerWithSentry(defaultStreamHandler));
164179
```
165180

166-
Add the `sentryGlobalServerMiddlewareHandler` to your global middlewares to instrument your server function invocations:
181+
### Instrument Server Functions
182+
183+
Add the Sentry middleware handler to your global middlewares in `src/global-middleware.ts` to instrument your server function invocations:
167184

168185
<Alert level="info">
169186

170-
If you haven't done so, create a `src/global-middleware.ts` file as outlined in the [TanStack Start Docs for Global Middleware](https://tanstack.com/start/latest/docs/framework/react/middleware#global-middleware).
187+
If you haven't created `src/global-middleware.ts` file, follow the [TanStack Start documentation for Global Middleware](https://tanstack.com/start/latest/docs/framework/react/middleware#global-middleware) to set it up.
171188

172189
</Alert>
173190

@@ -187,17 +204,19 @@ registerGlobalMiddleware({
187204
});
188205
```
189206

190-
### Capture Errors in your Error Boundaries and Components
207+
### Capturing Errors in Error Boundaries and Components (Optional)
191208

192209
<Alert level="info">
193-
Automatic error monitoring is not yet supported on the on the server-side of
194-
TanStack Start. Use `captureException` to manually capture errors in your
195-
server-side code.
210+
Automatic error monitoring is not yet supported on the server side of TanStack
211+
Start. Use `captureException` to manually capture errors in your server-side
212+
code.
196213
</Alert>
197214

198-
The Sentry SDK cannot capture errors that you manually caught yourself with error boundaries.
215+
Sentry automatically captures unhandled client-side errors. Errors caught by your own error boundaries aren't captured unless you report them manually:
199216

200-
If you have React error boundaries in your app and you want to report errors that these boundaries catch to Sentry, apply the [`withErrorBoundary` wrapper](/platforms/javascript/guides/react/features/error-boundary/) to your `ErrorBoundary`:
217+
#### Custom Error Boundary
218+
219+
Wrap your custom `ErrorBoundary` component with [`withErrorBoundary`](/platforms/javascript/guides/react/features/error-boundary/):
201220

202221
```tsx
203222
import React from "react";
@@ -215,7 +234,9 @@ export const MySentryWrappedErrorBoundary = Sentry.withErrorBoundary(
215234
);
216235
```
217236

218-
If you defined `errorComponent`s in your Code-Based TanStack Router routes, capture the `error` argument with `captureException` inside a `useEffect` hook:
237+
#### TanStack Router `errorComponent`
238+
239+
Use Sentry's `captureException` function inside a `useEffect` hook within your `errorComponent`:
219240

220241
```tsx {2,6-8}
221242
import { createRoute } from "@tanstack/react-router";
@@ -234,13 +255,17 @@ const route = createRoute({
234255
})
235256
```
236257

237-
## Step 3: Verify
258+
## Step 4: Avoid Ad Blockers With Tunneling (Optional)
259+
260+
<PlatformContent includePath="getting-started-tunneling" />
261+
262+
## Step 5: Verify
238263

239264
Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.
240265

241266
### Issues
242267

243-
To verify that Sentry captures errors and creates issues in your Sentry project, add a test button to an existing page or create a new one:
268+
To verify that Sentry captures errors and creates issues in your Sentry project, add a test button to one of your pages, which will trigger an error that Sentry will capture when you click it:
244269

245270
```tsx
246271
<button
@@ -262,16 +287,15 @@ To verify that Sentry captures errors and creates issues in your Sentry project,
262287
<OnboardingOption optionId="performance">
263288
### Tracing
264289

265-
To test tracing, create a test API route like `/api/sentry-example-api`:
290+
To test tracing, create a new file like `src/routes/sentry-example.ts` to create a test route `/sentry-example`:
266291

267-
```typescript {filename:src/routes/api/sentry-example-api.ts}
292+
```typescript {filename:src/routes/sentry-example.ts}
293+
import { createServerFileRoute } from "@tanstack/react-start/server";
268294
import { json } from "@tanstack/react-start";
269-
import { createAPIFileRoute } from "@tanstack/react-start/api";
270295

271-
// A faulty API route to test Sentry's error monitoring
272-
export const APIRoute = createAPIFileRoute("/api/sentry-example-api")({
273-
GET: ({ request, params }) => {
274-
throw new Error("Sentry Example API Route Error");
296+
export const ServerRoute = createServerFileRoute("/sentry-example").methods({
297+
GET: async ({ request }) => {
298+
throw new Error("Sentry Example Route Error");
275299
return json({ message: "Testing Sentry Error..." });
276300
},
277301
});
@@ -289,7 +313,7 @@ Next, update your test button to call this route and throw an error if the respo
289313
op: "test",
290314
},
291315
async () => {
292-
const res = await fetch("/api/sentry-example-api");
316+
const res = await fetch("/sentry-example");
293317
if (!res.ok) {
294318
throw new Error("Sentry Example Frontend Error");
295319
}
@@ -318,16 +342,18 @@ Now, head over to your project on [Sentry.io](https://sentry.io) to view the col
318342

319343
## Next Steps
320344

321-
At this point, you should have integrated Sentry into your TanStack Start application and should already be sending data to your Sentry project.
345+
At this point, you should have integrated Sentry into your TanStack Start React application and should already be sending data to your Sentry project.
322346

323347
Now's a good time to customize your setup and look into more advanced topics.
324348
Our next recommended steps for you are:
325349

326350
- Learn how to [manually capture errors](/platforms/javascript/guides/tanstackstart-react/usage/)
327351
- Continue to [customize your configuration](/platforms/javascript/guides/tanstackstart-react/configuration/)
352+
- Get familiar with [Sentry's product features](/product/) like tracing, insights, and alerts
328353

329354
<Expandable permalink={false} title="Are you having problems setting up the SDK?">
330355

356+
- Find various topics in <PlatformLink to="/troubleshooting">Troubleshooting</PlatformLink>
331357
- [Get support](https://sentry.zendesk.com/hc/en-us/)
332358

333359
</Expandable>

0 commit comments

Comments
 (0)