Skip to content

Commit 3ef44a4

Browse files
author
Luca Forstner
authored
ref: Remove deprecated showReportDialog APIs (#10609)
1 parent b62eecb commit 3ef44a4

File tree

8 files changed

+55
-81
lines changed

8 files changed

+55
-81
lines changed

packages/angular/src/errorhandler.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { HttpErrorResponse } from '@angular/common/http';
22
import type { ErrorHandler as AngularErrorHandler } from '@angular/core';
33
import { Inject, Injectable } from '@angular/core';
44
import * as Sentry from '@sentry/browser';
5+
import type { ReportDialogOptions } from '@sentry/browser';
56
import type { Event } from '@sentry/types';
67
import { isString } from '@sentry/utils';
78

@@ -13,8 +14,7 @@ import { runOutsideAngular } from './zone';
1314
export interface ErrorHandlerOptions {
1415
logErrors?: boolean;
1516
showDialog?: boolean;
16-
// eslint-disable-next-line deprecation/deprecation
17-
dialogOptions?: Omit<Sentry.ReportDialogOptions, 'eventId'>;
17+
dialogOptions?: Omit<ReportDialogOptions, 'eventId'>;
1818
/**
1919
* Custom implementation of error extraction from the raw value captured by the Angular.
2020
* @param error Value captured by Angular's ErrorHandler provider
@@ -120,8 +120,7 @@ class SentryErrorHandler implements AngularErrorHandler {
120120

121121
if (client && !this._registeredAfterSendEventHandler) {
122122
client.on('afterSendEvent', (event: Event) => {
123-
if (!event.type) {
124-
// eslint-disable-next-line deprecation/deprecation
123+
if (!event.type && event.event_id) {
125124
Sentry.showReportDialog({ ...this._options.dialogOptions, eventId: event.event_id });
126125
}
127126
});

packages/angular/test/errorhandler.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ describe('SentryErrorHandler', () => {
514514
expect(client.on).toHaveBeenCalledWith('afterSendEvent', expect.any(Function));
515515

516516
// this simulates the afterSend hook being called
517-
client.cb({});
517+
client.cb({ event_id: 'foobar' });
518518

519519
expect(showReportDialogSpy).toBeCalledTimes(1);
520520
});

packages/browser/src/exports.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ export type {
1717

1818
export type { BrowserOptions } from './client';
1919

20-
// eslint-disable-next-line deprecation/deprecation
21-
export type { ReportDialogOptions } from './helpers';
20+
export type { ReportDialogOptions } from './sdk';
2221

2322
export {
2423
// eslint-disable-next-line deprecation/deprecation

packages/browser/src/helpers.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { browserTracingIntegration } from '@sentry-internal/tracing';
22
import { BrowserTracing } from '@sentry-internal/tracing';
33
import { captureException, withScope } from '@sentry/core';
4-
import type { DsnLike, Integration, Mechanism, WrappedFunction } from '@sentry/types';
4+
import type { Integration, Mechanism, WrappedFunction } from '@sentry/types';
55
import {
66
GLOBAL_OBJ,
77
addExceptionMechanism,
@@ -156,38 +156,6 @@ export function wrap(
156156
return sentryWrapped;
157157
}
158158

159-
/**
160-
* All properties the report dialog supports
161-
*
162-
* @deprecated This type will be removed in the next major version of the Sentry SDK. `showReportDialog` will still be around, however the `eventId` option will now be required.
163-
*/
164-
export interface ReportDialogOptions {
165-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
166-
[key: string]: any;
167-
eventId?: string;
168-
dsn?: DsnLike;
169-
user?: {
170-
email?: string;
171-
name?: string;
172-
};
173-
lang?: string;
174-
title?: string;
175-
subtitle?: string;
176-
subtitle2?: string;
177-
labelName?: string;
178-
labelEmail?: string;
179-
labelComments?: string;
180-
labelClose?: string;
181-
labelSubmit?: string;
182-
errorGeneric?: string;
183-
errorFormEntry?: string;
184-
successMessage?: string;
185-
/** Callback after reportDialog showed up */
186-
onLoad?(this: void): void;
187-
/** Callback after reportDialog closed */
188-
onClose?(this: void): void;
189-
}
190-
191159
/**
192160
* This is a slim shim of `browserTracingIntegration` for the CDN bundles.
193161
* Since the actual functional integration uses a different code from `BrowserTracing`,

packages/browser/src/sdk.ts

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import type { Hub } from '@sentry/core';
1+
import { getCurrentScope } from '@sentry/core';
22
import { functionToStringIntegration, inboundFiltersIntegration } from '@sentry/core';
33
import {
44
captureSession,
55
getClient,
6-
getCurrentHub,
76
getIntegrationsToSetup,
87
getReportDialogEndpoint,
98
initAndBind,
109
startSession,
1110
} from '@sentry/core';
12-
import type { Integration, Options, UserFeedback } from '@sentry/types';
11+
import type { DsnLike, Integration, Options, UserFeedback } from '@sentry/types';
1312
import {
1413
addHistoryInstrumentationHandler,
1514
logger,
@@ -20,7 +19,6 @@ import {
2019
import type { BrowserClientOptions, BrowserOptions } from './client';
2120
import { BrowserClient } from './client';
2221
import { DEBUG_BUILD } from './debug-build';
23-
import type { ReportDialogOptions } from './helpers';
2422
import { WINDOW, wrap as internalWrap } from './helpers';
2523
import { breadcrumbsIntegration } from './integrations/breadcrumbs';
2624
import { dedupeIntegration } from './integrations/dedupe';
@@ -139,42 +137,52 @@ export function init(options: BrowserOptions = {}): void {
139137
}
140138
}
141139

142-
type NewReportDialogOptions = ReportDialogOptions & { eventId: string }; // eslint-disable-line
143-
144-
interface ShowReportDialogFunction {
145-
/**
146-
* Present the user with a report dialog.
147-
*
148-
* @param options Everything is optional, we try to fetch all info need from the global scope.
149-
*/
150-
(options: NewReportDialogOptions): void;
151-
152-
/**
153-
* Present the user with a report dialog.
154-
*
155-
* @param options Everything is optional, we try to fetch all info need from the global scope.
156-
*
157-
* @deprecated Please always pass an `options` argument with `eventId`. The `hub` argument will not be used in the next version of the SDK.
158-
*/
159-
// eslint-disable-next-line deprecation/deprecation
160-
(options?: ReportDialogOptions, hub?: Hub): void;
140+
/**
141+
* All properties the report dialog supports
142+
*/
143+
export interface ReportDialogOptions {
144+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
145+
[key: string]: any;
146+
eventId: string;
147+
dsn?: DsnLike;
148+
user?: {
149+
email?: string;
150+
name?: string;
151+
};
152+
lang?: string;
153+
title?: string;
154+
subtitle?: string;
155+
subtitle2?: string;
156+
labelName?: string;
157+
labelEmail?: string;
158+
labelComments?: string;
159+
labelClose?: string;
160+
labelSubmit?: string;
161+
errorGeneric?: string;
162+
errorFormEntry?: string;
163+
successMessage?: string;
164+
/** Callback after reportDialog showed up */
165+
onLoad?(this: void): void;
166+
/** Callback after reportDialog closed */
167+
onClose?(this: void): void;
161168
}
162169

163-
export const showReportDialog: ShowReportDialogFunction = (
164-
// eslint-disable-next-line deprecation/deprecation
165-
options: ReportDialogOptions = {},
166-
// eslint-disable-next-line deprecation/deprecation
167-
hub: Hub = getCurrentHub(),
168-
) => {
170+
/**
171+
* Present the user with a report dialog.
172+
*
173+
* @param options Everything is optional, we try to fetch all info need from the global scope.
174+
*/
175+
export function showReportDialog(options: ReportDialogOptions): void {
169176
// doesn't work without a document (React Native)
170177
if (!WINDOW.document) {
171178
DEBUG_BUILD && logger.error('Global document not defined in showReportDialog call');
172179
return;
173180
}
174181

175-
// eslint-disable-next-line deprecation/deprecation
176-
const { client, scope } = hub.getStackTop();
177-
const dsn = options.dsn || (client && client.getDsn());
182+
const scope = getCurrentScope();
183+
const client = scope.getClient();
184+
const dsn = client && client.getDsn();
185+
178186
if (!dsn) {
179187
DEBUG_BUILD && logger.error('DSN not configured for showReportDialog call');
180188
return;
@@ -216,7 +224,7 @@ export const showReportDialog: ShowReportDialogFunction = (
216224
} else {
217225
DEBUG_BUILD && logger.error('Not injecting report dialog. No injection point found in HTML');
218226
}
219-
};
227+
}
220228

221229
/**
222230
* This function is here to be API compatible with the loader.

packages/browser/test/unit/index.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('SentryBrowser', () => {
8888
setCurrentClient(client);
8989

9090
// eslint-disable-next-line deprecation/deprecation
91-
showReportDialog();
91+
showReportDialog({ eventId: 'foobar' });
9292

9393
expect(getReportDialogEndpoint).toHaveBeenCalledTimes(1);
9494
expect(getReportDialogEndpoint).toHaveBeenCalledWith(
@@ -103,7 +103,7 @@ describe('SentryBrowser', () => {
103103

104104
const DIALOG_OPTION_USER = { email: '[email protected]' };
105105
// eslint-disable-next-line deprecation/deprecation
106-
showReportDialog({ user: DIALOG_OPTION_USER });
106+
showReportDialog({ eventId: 'foobar', user: DIALOG_OPTION_USER });
107107

108108
expect(getReportDialogEndpoint).toHaveBeenCalledTimes(1);
109109
expect(getReportDialogEndpoint).toHaveBeenCalledWith(
@@ -137,7 +137,7 @@ describe('SentryBrowser', () => {
137137
it('should call `onClose` when receiving `__sentry_reportdialog_closed__` MessageEvent', async () => {
138138
const onClose = jest.fn();
139139
// eslint-disable-next-line deprecation/deprecation
140-
showReportDialog({ onClose });
140+
showReportDialog({ eventId: 'foobar', onClose });
141141

142142
await waitForPostMessage('__sentry_reportdialog_closed__');
143143
expect(onClose).toHaveBeenCalledTimes(1);
@@ -152,7 +152,7 @@ describe('SentryBrowser', () => {
152152
throw new Error();
153153
});
154154
// eslint-disable-next-line deprecation/deprecation
155-
showReportDialog({ onClose });
155+
showReportDialog({ eventId: 'foobar', onClose });
156156

157157
await waitForPostMessage('__sentry_reportdialog_closed__');
158158
expect(onClose).toHaveBeenCalledTimes(1);
@@ -165,7 +165,7 @@ describe('SentryBrowser', () => {
165165
it('should not call `onClose` for other MessageEvents', async () => {
166166
const onClose = jest.fn();
167167
// eslint-disable-next-line deprecation/deprecation
168-
showReportDialog({ onClose });
168+
showReportDialog({ eventId: 'foobar', onClose });
169169

170170
await waitForPostMessage('some_message');
171171
expect(onClose).not.toHaveBeenCalled();

packages/nextjs/test/integration/pages/reportDialog.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { showReportDialog } from '@sentry/nextjs';
1+
import { captureException, showReportDialog } from '@sentry/nextjs';
22

33
const ReportDialogPage = (): JSX.Element => (
44
<button
55
onClick={() => {
6-
showReportDialog();
6+
const eventId = captureException(new Error('show-report-dialog-error'));
7+
showReportDialog({ eventId });
78
}}
89
>
910
Open Report Dialog

packages/react/src/errorboundary.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export type ErrorBoundaryProps = {
2828
* Options to be passed into the Sentry report dialog.
2929
* No-op if {@link showDialog} is false.
3030
*/
31-
// eslint-disable-next-line deprecation/deprecation
3231
dialogOptions?: Omit<ReportDialogOptions, 'eventId'> | undefined;
3332
/**
3433
* A fallback component that gets rendered when the error boundary encounters an error.

0 commit comments

Comments
 (0)