sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Can't do away with deprecated warning for showReportDialog()

Open pcnova opened this issue 2 years ago • 2 comments

Is there an existing issue for this?

  • [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • [X] I have reviewed the documentation https://docs.sentry.io/
  • [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/react

SDK Version

7.94.1

Framework Version

17.0.2

Link to Sentry event

No response

SDK Setup

Sentry.init({
  dsn: '[OMMITTED]',
  environment: process.env.NODE_ENV,
  autoSessionTracking: false,
  beforeSend(event) {
    if (process.env.NODE_ENV === 'production') {
      // Determine if our error handler dealt with this
      const handled =
        event.contexts && event.contexts[sentryErrorHandledProperty];

      if (!handled) {
        const opts: NewReportDialogOptions = { eventId: event.event_id };
        Sentry.showReportDialog(opts);
      }
      return event;
    }
    return null;
  },
});

Steps to Reproduce

  1. Try to use the Sentry.showReportDialog() anywhere, passing the newly-recommended {eventId: string} options object.
  2. See that the deprecated warning does not go away.
  3. If you try to enforce the typing so that TS knows you're trying to call the new overload of the method, you will get a compiler error because the new type is not exported, e.g.:
    Sentry.showReportDialog({ eventId: event.event_id } as NewReportDialogOptions);
    //                                                  Red squigglies here ^
    

Expected Result

I should be able to remove the deprecation warning.

Actual Result

Sentry unexported type

pcnova avatar Jan 19 '24 22:01 pcnova

I didn't find a typescript setting that enforces deprecations not to be used. We have a lint rule in our repo that screams when we use deprecations but it works perfectly well with the setup we have:

https://github.com/getsentry/sentry-javascript/assets/8118419/731d0306-be7c-486c-8bdd-55c7d42a55c5

You are likely seeing issues because event.event_id is of type string | undefined which will infer the deprecated type. I should adjust this in the migration guide and docs to do this instead:

if (event. event_id) {
  Sentry.showReportDialog({ eventId: event_id })
}

lforst avatar Jan 22 '24 09:01 lforst

I didn't find a typescript setting that enforces deprecations not to be used. We have a lint rule in our repo that screams when we use deprecations but it works perfectly well with the setup we have:

Screen.Recording.2024-01-22.at.10.25.45.mov You are likely seeing issues because event.event_id is of type string | undefined which will infer the deprecated type. I should adjust this in the migration guide and docs to do this instead:

if (event. event_id) {
  Sentry.showReportDialog({ eventId: event_id })
}

Ah, you are right: ensuring the parameter is string, as opposed to string | undefined does away with the warning! I missed that when testing.

It would be good to update the docs for this, as you say. Anyway, thanks for the quick response.

pcnova avatar Jan 22 '24 22:01 pcnova