Skip to content

feat(browser): add LoaderSentry type - #25357

Merged
Lms24 merged 4 commits into
getsentry:developfrom
faizansaiyed123:feat/loader-sentry-type
Oct 16, 2026
Merged

Lms24 merged 4 commits into
getsentry:developfrom
faizansaiyed123:feat/loader-sentry-type

Conversation

@faizansaiyed123

Copy link
Copy Markdown
Contributor

Summary

Adds an exported LoaderSentry type for TypeScript users of the CDN loader.

Changes

  • Adds and exports LoaderSentry.
  • Represents the APIs supported by the loader stub.
  • Uses void return types for queued methods to match the loader's runtime behavior.
  • Adds type tests covering supported and unsupported APIs.

This is a TypeScript-only solution and does not change the loader runtime behavior or expand the loader's queued method list.

Related to #21806.

@faizansaiyed123
faizansaiyed123 requested a review from a team as a code owner October 14, 2026 09:39
@faizansaiyed123
faizansaiyed123 requested review from logaretm and msonnb and removed request for a team October 14, 2026 09:39
@github-actions github-actions Bot added the external PR from an external contributor label Oct 14, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1c7706b. Configure here.

Comment thread packages/browser/test/loader-types.test-d.ts
@faizansaiyed123

Copy link
Copy Markdown
Contributor Author

Hi @Lms24, thanks for approving the TypeScript-only approach on #21806.

I've opened #25357, added the focused type tests, and addressed the BugBot feedback. The latest BugBot review found no issues, and the focused type tests pass locally.

The GitHub Actions workflows appear to be awaiting approval for this fork PR. Could you or another maintainer approve them so CI can run?

Thanks for your time!

@Lms24

Lms24 commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

I made some changes to this PR to get it passing with our lint rules and also make the type imports and exports a bit simpler.

  • Replaced typeof import() with named import type statements, because the repo's lint rule bans import() type annotations.
  • Replaced the mapped type with an explicit LoaderSentry interface that lists each safe method.
  • withScope now only takes the single-callback form, so withScope(scope => …) type-checks. in the loader you can't really pass a scope to withScope
  • Added a JSDoc usage example to LoaderSentry, including that when LoaderSentry is declared via global, a type cast needs to happen in Sentry.onLoad where all APIs can be accessed safely and have their original signature again.
  • Renamed src/loader.ts to src/loader-types.ts so it doesn't look like loader runtime code.
  • Added type tests that check method parameters and the withScope signature.
  • Deleted tsconfig.loader.test.json and pointed typecheck at the shared tsconfig.test.json, as packages/cloudflare does.
  • Added ignoreSourceErrors: true, because 37 type errors already in other browser test files would otherwise fail the run.
  • Formatting

@Lms24 Lms24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing!

faizansaiyed123 and others added 4 commits October 16, 2026 12:22
Replace the `typeof import()` type annotations, which the
consistent-type-imports lint rule rejects, with named type imports and
an explicit interface. Type `withScope` with only its callback overload,
since inferring from the overloaded function kept just the two-argument
form. Add a usage example and rename the file to loader-types.ts.

Run the type tests with the shared tsconfig.test.json and
ignoreSourceErrors, like the cloudflare package does.

Refs getsentry#21806
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Inside an `onLoad` callback the full SDK is loaded, but the loader calls
the callback without arguments, so the type can't express this. Document
casting `window.Sentry` to the full SDK type instead.

Refs getsentry#21806
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Lms24
Lms24 force-pushed the feat/loader-sentry-type branch from 9d21b2a to 14abcc2 Compare October 16, 2026 10:23
@Lms24
Lms24 enabled auto-merge (squash) October 16, 2026 10:27
@Lms24
Lms24 merged commit f4a3cba into getsentry:develop Oct 16, 2026
420 of 422 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external PR from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Loader stub silently drops calls outside queued method list, which results in either silent no-ops

2 participants