getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.97k stars 1.57k forks source link

react: Sentry.ErrorBoundary showDialog doesn't infer user #3257

Closed zanona closed 3 years ago

zanona commented 3 years ago

Package + Version

Version:

"@sentry/react": "^6.1.0"

Description

https://codesandbox.io/s/sentry-show-dialog-user-d1lgw?file=/src/index.js

Whenever using the property showDialog on <Sentry.ErrorBoundary>, even though the user has been set previously, the dialog won't infer those settings and autofill the name and email fields on the widget form.

import React, { useEffect, useState } from "react";
import ReactDOM from "react-dom";
import * as Sentry from "@sentry/react";

Sentry.init({
  dsn: process.env.SENTRY_DSN //ADD YOURS
});

function App() {
  const [foo, setFoo] = useState("ahoy");
  useEffect(() => {
    Sentry.setUser({ email: "foo@bar.com", name: "Foobar" });
  }, []);

  return (
    <Sentry.ErrorBoundary showDialog fallback={<h1>Error</h1>}>
      <h1>Hello {foo}</h1>
      <button onClick={() => setFoo({ foo: true })}>Break the world</button>
    </Sentry.ErrorBoundary>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
AbhiPrasad commented 3 years ago

This is fixed by https://github.com/getsentry/sentry-javascript/pull/3792.