Skip to content

Commit 3036000

Browse files
committed
clarify annotations problem and possible solution / workaround
1 parent 274f9d0 commit 3036000

File tree

2 files changed

+32
-24
lines changed
  • app/web_development
    • posts/sentry-io
    • tutorials/next-js-static-first-mdx-starterkit/error-handling-and-logging

2 files changed

+32
-24
lines changed

app/web_development/posts/sentry-io/page.mdx

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Sentry.io
33
keywords: ['Sentry.io', 'logging', 'debugging', 'SaaS', 'wizard']
44
published: 2024-08-07T11:22:33.444Z
5-
modified: 2024-09-02T16:16:16.444Z
5+
modified: 2025-06-02T16:16:16.444Z
66
permalink: https://chris.lu/web_development/posts/sentry-io
77
section: Web development
88
---
@@ -206,28 +206,42 @@ To enable Sentry **reactComponentAnnotation** configuration option is usually a
206206
207207
### Issues with Sentry Component Annotations
208208

209-
To make this feature happen Sentry needs to add a data attributes to components, this does usually not pose a problem except sometimes the Sentry Annotations on third party components will cause an error in those third party tools, like [react-three-fiber](https://github.com/pmndrs/react-three-fiber) which do NOT like those extra attributes at all
209+
For the **Sentry Component Annotation** feature to work, Sentry adds a `data-sentry` data attribute to the DOM of React components.
210210

211-
This means that **React component annotations** are great unless you use a package like **React Three Fiber** or setup your project using **Vite**, then you need to disable the feature
211+
This does usually not pose a problem except with some packages that are incompatible. For example if you enable **Component Annotations** and use [@react-three/fiber](https://github.com/pmndrs/react-three-fiber) then you might see the following error ([Sentry Issue #530](https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/530)) popping up in your terminal:
212212

213-
#### React three fiber (R3F) issue
213+
> TypeError: Cannot read properties of undefined (reading 'sentry')
214214
215-
For now if you use **React three fiber (R3F)** the only workaround is to turn the Sentry **React component annotations** option off, by setting the `reactComponentAnnotation` variable to false
215+
A similar [Issue #492](https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/492) has impacted vite users
216216

217-
It is only after I had opened an [Issue #13413](https://github.com/getsentry/sentry-javascript/issues/13413) in the **sentry-javascript** repository that I found the [Issue #530 (Cannot read properties of undefined (reading 'sentry') when using reactComponentAnnotation)](https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/530) in the **sentry-javascript-bundler-plugins** repository, which has a comment by one of the Sentry SDK maintainers, they mentioned that they consider adding more options in the future to let you exclude components
217+
<span className="neonBlueHighlightedText">Option 1</span> (just a workaround): Is to disable the feature by setting the **reactComponentAnnotation** configuration option to **false**:
218218

219-
However as of now those options are not available yet (we can NOT enable React component annotations and exclude React three fiber), meaning the only option left is to disable the reactComponentAnnotation feature (if you chose to continue using R3F)
219+
```js
220+
reactComponentAnnotation: {
221+
enabled: false,
222+
},
223+
```
220224

221-
> [!MORE]
222-
> [Sentry "Issue #530" (open as of dec. 2024)](https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/530)
225+
<span className="neonBlueHighlightedText">Option 2</span> (only available in Sentry > 9):
223226

224-
#### Vite issue
227+
The sentry-javascript-bundler-plugins [PR #617](https://github.com/getsentry/sentry-javascript-bundler-plugins/pull/617) has added a new **ignoredComponents** configuration option, that lets you tell Sentry which components should get ignored, meaning for those components Sentry will not try to add extra attributes to their DOM
225228

226-
There is a similar issue when using Vite and the @sentry/vite-plugin as described in the [Issue #492](https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/492) which (as of dec. 2024) is also still open
229+
```js
230+
reactComponentAnnotation: {
231+
enabled: true,
232+
ignoredComponents: ['MY_COMPONENT_WHICH_BREAKS'],
233+
},
234+
```
227235

228-
Same as R3F, the only solution here is to NOT enable the annotations feature until the problem is fixed
236+
> [!WARN]
237+
> The first **sentry-javascript-bundler-plugins** version with support for the Sentry **ignoredComponents** is [version 2.23.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/releases/tag/2.23.0).
238+
>
239+
> @Sentry/Next.js v8.45.0 still uses @sentry/bundler-plugin-core / @sentry/webpack-plugin v2.22.7
240+
>
241+
> @Sentry/Next.js v9.0.1 has (@sentry/webpack-plugin) v3.1.2 as dependency, so this is the first version that has the new **ignoredComponents** feature merged
229242
230243
> [!MORE]
231-
> [Sentry "Issue #492" (open as of dec. 2024)](https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/530)
244+
> [Sentry bundler "Issue #530"](https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/530)
245+
> [Sentry bundler "PR #617"](https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/530)
232246
233247
</article>

app/web_development/tutorials/next-js-static-first-mdx-starterkit/error-handling-and-logging/page.mdx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Error handling and logging - Next.js 15 Tutorial
33
description: Error handling and logging - Next.js 15 static first MDX starterkit | Web development tutorials | www.chris.lu
44
keywords: ['error', 'handling', 'logging', 'Boundary', 'react', 'sentry.io', 'nextjs']
55
published: 2024-12-31T23:00:00.000Z
6-
modified: 2024-12-31T23:00:00.000Z
6+
modified: 2025-06-02T23:00:00.000Z
77
permalink: https://chris.lu/web_development/tutorials/next-js-static-first-mdx-starterkit/error-handling-and-logging
88
section: Web development
99
---
@@ -202,11 +202,7 @@ Now, Sentry will install the latest Sentry SDK for Next.js.
202202
**Do you want to enable React component annotations to make breadcrumbs and session replays more readable?** Next Sentry is asking if we want to use the feature called [React component annotations](https://docs.sentry.io/platforms/javascript/guides/react/features/component-names/) which attempts to use component names in reports instead of more cryptic selectors, I think this is a nice feature, so I selected **Yes**, if you already use Sentry.io and don't want to change how bug reports work, then leave it on **No**, you can always turn it on/off via the configuration later if you want
203203

204204
> [!WARN]
205-
> I turned **React component annotations** on and then noticed that my [react-three-fiber](https://github.com/pmndrs/react-three-fiber) animation had stopped working, this is because **React component annotations** adds data attributes to components which React Three Fiber does not like, and which then creates bugs which print the following in your console:
206-
>
207-
> > TypeError: Cannot read properties of undefined (reading 'sentry')
208-
>
209-
> So if you plan on using **React Three Fiber** then you should answer to this question with **NO**, to learn more about this problem and how to disable **React component annotations** manually in the configuration have a look at the [Sentry React Component Annotation(s) can be problematic](#sentry-react-component-annotations-can-be-problematic) chapter
205+
> be aware that some packages might have a problem with the extra attributes that Sentry adds to the DOM of a component, to make the Annotations feature work. If you want to learn more about this problem, then I recommend reading the ["Issues with Sentry Component Annotations" chapter of the "Sentry" post](/web_development/posts/sentry-io#issues-with-sentry-component-annotations)
210206
211207
**Do you want to create an example page** chose **YES** (we will later use it to test the Sentry setup, and then we will delete it)
212208

@@ -328,13 +324,11 @@ Now is a good time to commit the updated `next.config.ts` (and other changes the
328324
329325
### Sentry React Component Annotation(s) can be problematic
330326

331-
To enable Sentry **reactComponentAnnotation** configuration option is usually a good idea as it makes reports more readable by using component names instead of long selectors
332-
333-
To make this feature happen Sentry needs to add a data attributes to components, this does usually not pose a problem except sometimes the Sentry Annotations on third party components will cause an error in those third party tools
327+
It is usually a good idea enable Sentry **reactComponentAnnotation** configuration option, as it makes reports more readable by using component names instead of long selectors
334328

335-
I have a more detailed explanation about annotations and the problems that can occur in my [Sentry Post](/web_development/posts/sentry-io)
329+
To make the Annotation(s) feature work, Sentry needs to add a data attributes to components, this does usually not pose a problem except in some situations where the Sentry Annotations on a third party components will cause an error in those third party package.
336330

337-
The solution to these problems is to disable the feature and wait for the Sentry team to fine tune the feature (which is quite young) and fix annotations bugs (I have linked to some tickets in my Sentry post, you may want to subscribe to them if you want to keep track of fixes)
331+
For those that run into problems after enabling the React Component Annotations feature, I have added a more detailed explanation as well as a workaround in the ["Issues with Sentry Component Annotations" chapter of the "Sentry" post](/web_development/posts/sentry-io#issues-with-sentry-component-annotations)
338332

339333
> [!MORE]
340334
> [chris.lu "Sentry.io" post](/web_development/posts/sentry-io)

0 commit comments

Comments
 (0)