docs(angular): Fix snippets that fail to compile - #19333
Conversation
Three snippets in the Angular guide don't build under the tsconfig `ng new` generates, from the runtime docs audit (SDK-1506). - `manual-setup` called `inject(TraceService)` while importing only `Sentry`, so `ng build` failed with `TS2304 Cannot find name 'TraceService'`. Call `inject(Sentry.TraceService)` - The custom error handler declared `handleError` without `override`, which `noImplicitOverride` rejects with `TS4114` - The component tracking examples used `OnChanges`, `OnDestroy` and `SimpleChanges` without importing them, and the paired template read a `user` input the class never declared. Import what they use, declare the input, and drop the two child components the example doesn't define Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
|
Please update the IS YOUR CHANGE URGENT? section of the PR description:
This information helps the Docs team prioritize your review. |
| <span trace="user-icon">user</span> | ||
| <label>{{ user.name }}</label> | ||
| <!--...--> | ||
| <app-button trace="save-user">Save</app-button> | ||
| <button trace="save-user">Save</button> |
There was a problem hiding this comment.
h: why these changes? the directive should apply to a component, not a primitive html element. I think it's totally fine to reference a child component that's not defined fwiw.
There was a problem hiding this comment.
You're right. Thought when copy pasting that snippet it would fail, when there is no app-icon or app-button. But if it is ok when child components are not defined then I'll revert it
There was a problem hiding this comment.
yeah it should just demonstrate how to use the directive. If you wanna add components somewhere in the snippet it's fine but I'd argue it's not necessary for brevity.
| } | ||
|
|
||
| handleError(error: any): void { | ||
| override handleError(error: any): void { |
There was a problem hiding this comment.
m: is this valid syntax? Angular docs for error handlers don't mention an override: https://angular.dev/api/core/ErrorHandler#usage-notes
There was a problem hiding this comment.
Interesting. I (... Claude) created a new project with ng new and it creates a tsconfig with "noImplicitOverride": true (tested probe)
When leaving "noImplicitOverride": true, which is the default, I'll get this error:
There was a problem hiding this comment.
hmm okay, maybe the angular docs are out of date 😅
tbh, I never saw this before but if this is how Angular scaffolds a project by default, then let's use it :)
There was a problem hiding this comment.
l: I'd suggest we change this since defining a name in the decorator avoids potentially skewed names due to minification
| @Sentry.TraceMethod({ name: "UserCard.ngOnChanges" }) | |
| ngOnChanges(changes: SimpleChanges) {} | |
| @Sentry.TraceMethod({ name: "UserCard.ngOnDestroy" }) |
| @Sentry.TraceClass({ name: "UserCard" }) | ||
| export class UserCardComponent implements OnChanges, OnDestroy { | ||
| @Sentry.TraceMethod() | ||
| @Input() user!: { name: string }; | ||
|
|
||
| @Sentry.TraceMethod({ name: "UserCard.ngOnChanges" }) | ||
| ngOnChanges(changes: SimpleChanges) {} | ||
|
|
||
| @Sentry.TraceMethod() | ||
| @Sentry.TraceMethod({ name: "UserCard.ngOnDestroy" }) | ||
| ngOnDestroy() {} | ||
| } | ||
| ``` |
There was a problem hiding this comment.
Bug: The HTML template in the Angular documentation example still uses <app-icon> and <app-button>, which are not defined, causing a compilation error.
Severity: MEDIUM
Suggested Fix
Remove the undefined <app-icon> and <app-button> elements from the user-card.component.html template snippet in the documentation. This will align the HTML with the component's definition and resolve the NG8001 compilation error, making the example code valid and buildable.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location:
docs/platforms/javascript/guides/angular/features/component-tracking.mdx#L103-L130
Potential issue: The pull request aimed to fix compilation errors in an Angular
documentation example but provided an incomplete solution. While the TypeScript code was
corrected, the associated HTML template snippet still includes the custom components
`<app-icon>` and `<app-button>`. These components are not defined or imported anywhere
in the example, which will lead to an `NG8001` compilation error when a user tries to
build the code. The PR description mentioned an intent to "drop the two child
components," but this change was not applied to the HTML.
Did we get this right? 👍 / 👎 to inform future reviews.
| } | ||
|
|
||
| handleError(error: any): void { | ||
| override handleError(error: any): void { |
There was a problem hiding this comment.
hmm okay, maybe the angular docs are out of date 😅
tbh, I never saw this before but if this is how Angular scaffolds a project by default, then let's use it :)
| <span trace="user-icon">user</span> | ||
| <label>{{ user.name }}</label> | ||
| <!--...--> | ||
| <app-button trace="save-user">Save</app-button> | ||
| <button trace="save-user">Save</button> |
There was a problem hiding this comment.
yeah it should just demonstrate how to use the directive. If you wanna add components somewhere in the snippet it's fine but I'd argue it's not necessary for brevity.
DESCRIBE YOUR PR
closes SDK-1506
Three snippets in the Angular guide don't build under the tsconfig
ng newgenerates, from the runtime docs audit (SDK-1506).manual-setupcalledinject(TraceService)while importing onlySentry, song buildfailed withTS2304 Cannot find name 'TraceService'. Callinject(Sentry.TraceService)handleErrorwithoutoverride, whichnoImplicitOverriderejects withTS4114OnChanges,OnDestroyandSimpleChangeswithout importing them, and the paired template read auserinput the class never declared. Import what they use, declare the input, and drop the two child components the example doesn't defineIS YOUR CHANGE URGENT?
Help us prioritize incoming PRs by letting us know when the change needs to go live.
Select exactly one option. For deadlines, replace
YYYY-MM-DDwith the due date. You can update this information later by editing the PR description.SLA
Thanks in advance for your help!
PRE-MERGE CHECKLIST
Make sure you've checked the following before merging your changes:
LEGAL BOILERPLATE
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.
EXTRA RESOURCES