@sentry/react 10.53.1 → 10.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/build/cjs/constants.js +3 -5
  2. package/build/cjs/constants.js.map +1 -1
  3. package/build/cjs/debug-build.js +0 -5
  4. package/build/cjs/debug-build.js.map +1 -1
  5. package/build/cjs/error.js +12 -72
  6. package/build/cjs/error.js.map +1 -1
  7. package/build/cjs/errorboundary.js +22 -77
  8. package/build/cjs/errorboundary.js.map +1 -1
  9. package/build/cjs/hoist-non-react-statics.js +16 -84
  10. package/build/cjs/hoist-non-react-statics.js.map +1 -1
  11. package/build/cjs/isSyntheticEvent.js +10 -0
  12. package/build/cjs/isSyntheticEvent.js.map +1 -0
  13. package/build/cjs/profiler.js +35 -110
  14. package/build/cjs/profiler.js.map +1 -1
  15. package/build/cjs/reactrouter-compat-utils/instrumentation.js +219 -690
  16. package/build/cjs/reactrouter-compat-utils/instrumentation.js.map +1 -1
  17. package/build/cjs/reactrouter-compat-utils/lazy-routes.js +24 -85
  18. package/build/cjs/reactrouter-compat-utils/lazy-routes.js.map +1 -1
  19. package/build/cjs/reactrouter-compat-utils/route-manifest.js +17 -95
  20. package/build/cjs/reactrouter-compat-utils/route-manifest.js.map +1 -1
  21. package/build/cjs/reactrouter-compat-utils/utils.js +48 -190
  22. package/build/cjs/reactrouter-compat-utils/utils.js.map +1 -1
  23. package/build/cjs/reactrouter.js +33 -113
  24. package/build/cjs/reactrouter.js.map +1 -1
  25. package/build/cjs/reactrouterv3.js +27 -59
  26. package/build/cjs/reactrouterv3.js.map +1 -1
  27. package/build/cjs/reactrouterv6.js +8 -41
  28. package/build/cjs/reactrouterv6.js.map +1 -1
  29. package/build/cjs/reactrouterv7.js +8 -41
  30. package/build/cjs/reactrouterv7.js.map +1 -1
  31. package/build/cjs/redux.js +60 -88
  32. package/build/cjs/redux.js.map +1 -1
  33. package/build/cjs/sdk.js +13 -8
  34. package/build/cjs/sdk.js.map +1 -1
  35. package/build/cjs/tanstackrouter.js +24 -64
  36. package/build/cjs/tanstackrouter.js.map +1 -1
  37. package/build/esm/constants.js +3 -5
  38. package/build/esm/constants.js.map +1 -1
  39. package/build/esm/debug-build.js +0 -5
  40. package/build/esm/debug-build.js.map +1 -1
  41. package/build/esm/error.js +12 -72
  42. package/build/esm/error.js.map +1 -1
  43. package/build/esm/errorboundary.js +22 -77
  44. package/build/esm/errorboundary.js.map +1 -1
  45. package/build/esm/hoist-non-react-statics.js +16 -84
  46. package/build/esm/hoist-non-react-statics.js.map +1 -1
  47. package/build/esm/isSyntheticEvent.js +8 -0
  48. package/build/esm/isSyntheticEvent.js.map +1 -0
  49. package/build/esm/package.json +1 -1
  50. package/build/esm/profiler.js +35 -110
  51. package/build/esm/profiler.js.map +1 -1
  52. package/build/esm/reactrouter-compat-utils/instrumentation.js +219 -690
  53. package/build/esm/reactrouter-compat-utils/instrumentation.js.map +1 -1
  54. package/build/esm/reactrouter-compat-utils/lazy-routes.js +24 -85
  55. package/build/esm/reactrouter-compat-utils/lazy-routes.js.map +1 -1
  56. package/build/esm/reactrouter-compat-utils/route-manifest.js +17 -95
  57. package/build/esm/reactrouter-compat-utils/route-manifest.js.map +1 -1
  58. package/build/esm/reactrouter-compat-utils/utils.js +48 -190
  59. package/build/esm/reactrouter-compat-utils/utils.js.map +1 -1
  60. package/build/esm/reactrouter.js +33 -113
  61. package/build/esm/reactrouter.js.map +1 -1
  62. package/build/esm/reactrouterv3.js +27 -59
  63. package/build/esm/reactrouterv3.js.map +1 -1
  64. package/build/esm/reactrouterv6.js +8 -41
  65. package/build/esm/reactrouterv6.js.map +1 -1
  66. package/build/esm/reactrouterv7.js +8 -41
  67. package/build/esm/reactrouterv7.js.map +1 -1
  68. package/build/esm/redux.js +60 -88
  69. package/build/esm/redux.js.map +1 -1
  70. package/build/esm/sdk.js +15 -10
  71. package/build/esm/sdk.js.map +1 -1
  72. package/build/esm/tanstackrouter.js +24 -64
  73. package/build/esm/tanstackrouter.js.map +1 -1
  74. package/build/types/isSyntheticEvent.d.ts +10 -0
  75. package/build/types/isSyntheticEvent.d.ts.map +1 -0
  76. package/build/types/sdk.d.ts.map +1 -1
  77. package/build/types-ts3.8/isSyntheticEvent.d.ts +10 -0
  78. package/package.json +3 -3
@@ -1,10 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const REACT_RENDER_OP = 'ui.react.render';
4
-
5
- const REACT_UPDATE_OP = 'ui.react.update';
6
-
7
- const REACT_MOUNT_OP = 'ui.react.mount';
3
+ const REACT_RENDER_OP = "ui.react.render";
4
+ const REACT_UPDATE_OP = "ui.react.update";
5
+ const REACT_MOUNT_OP = "ui.react.mount";
8
6
 
9
7
  exports.REACT_MOUNT_OP = REACT_MOUNT_OP;
10
8
  exports.REACT_RENDER_OP = REACT_RENDER_OP;
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["export const REACT_RENDER_OP = 'ui.react.render';\n\nexport const REACT_UPDATE_OP = 'ui.react.update';\n\nexport const REACT_MOUNT_OP = 'ui.react.mount';\n"],"names":[],"mappings":";;AAAO,MAAM,eAAA,GAAkB;;AAExB,MAAM,eAAA,GAAkB;;AAExB,MAAM,cAAA,GAAiB;;;;;;"}
1
+ {"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["export const REACT_RENDER_OP = 'ui.react.render';\n\nexport const REACT_UPDATE_OP = 'ui.react.update';\n\nexport const REACT_MOUNT_OP = 'ui.react.mount';\n"],"names":[],"mappings":";;AAAO,MAAM,eAAA,GAAkB;AAExB,MAAM,eAAA,GAAkB;AAExB,MAAM,cAAA,GAAiB;;;;;;"}
@@ -1,10 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- /**
4
- * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
5
- *
6
- * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
7
- */
8
3
  const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
9
4
 
10
5
  exports.DEBUG_BUILD = DEBUG_BUILD;
@@ -1 +1 @@
1
- {"version":3,"file":"debug-build.js","sources":["../../src/debug-build.ts"],"sourcesContent":["declare const __DEBUG_BUILD__: boolean;\n\n/**\n * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.\n *\n * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.\n */\nexport const DEBUG_BUILD = __DEBUG_BUILD__;\n"],"names":[],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACO,MAAM,WAAA,IAAc,OAAA,gBAAA,KAAA,WAAA,IAAA,gBAAA;;;;"}
1
+ {"version":3,"file":"debug-build.js","sources":["../../src/debug-build.ts"],"sourcesContent":["declare const __DEBUG_BUILD__: boolean;\n\n/**\n * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.\n *\n * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.\n */\nexport const DEBUG_BUILD = __DEBUG_BUILD__;\n"],"names":[],"mappings":";;AAOO,MAAM,WAAA,IAAc,OAAA,gBAAA,KAAA,WAAA,IAAA,gBAAA;;;;"}
@@ -4,101 +4,41 @@ const browser$1 = require('@sentry/browser');
4
4
  const browser = require('@sentry/core/browser');
5
5
  const React = require('react');
6
6
 
7
- /**
8
- * See if React major version is 17+ by parsing version string.
9
- */
10
7
  function isAtLeastReact17(reactVersion) {
11
8
  const reactMajor = reactVersion.match(/^([^.]+)/);
12
9
  return reactMajor !== null && parseInt(reactMajor[0]) >= 17;
13
10
  }
14
-
15
- /**
16
- * Recurse through `error.cause` chain to set cause on an error.
17
- */
18
11
  function setCause(error, cause) {
19
- const seenErrors = new WeakSet();
20
-
21
- function recurse(error, cause) {
22
- // If we've already seen the error, there is a recursive loop somewhere in the error's
23
- // cause chain. Let's just bail out then to prevent a stack overflow.
24
- if (seenErrors.has(error)) {
12
+ const seenErrors = /* @__PURE__ */ new WeakSet();
13
+ function recurse(error2, cause2) {
14
+ if (seenErrors.has(error2)) {
25
15
  return;
26
16
  }
27
- if (error.cause) {
28
- seenErrors.add(error);
29
- return recurse(error.cause, cause);
17
+ if (error2.cause) {
18
+ seenErrors.add(error2);
19
+ return recurse(error2.cause, cause2);
30
20
  }
31
- error.cause = cause;
21
+ error2.cause = cause2;
32
22
  }
33
-
34
23
  recurse(error, cause);
35
24
  }
36
-
37
- /**
38
- * Captures an error that was thrown by a React ErrorBoundary or React root.
39
- *
40
- * @param error The error to capture.
41
- * @param errorInfo The errorInfo provided by React.
42
- * @param hint Optional additional data to attach to the Sentry event.
43
- * @returns the id of the captured Sentry event.
44
- */
45
- function captureReactException(
46
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
- error,
48
- { componentStack },
49
- hint,
50
- ) {
51
- // If on React version >= 17, create stack trace from componentStack param and links
52
- // to to the original error using `error.cause` otherwise relies on error param for stacktrace.
53
- // Linking errors requires the `LinkedErrors` integration be enabled.
54
- // See: https://reactjs.org/blog/2020/08/10/react-v17-rc.html#native-component-stacks
55
- //
56
- // Although `componentDidCatch` is typed to accept an `Error` object, it can also be invoked
57
- // with non-error objects. This is why we need to check if the error is an error-like object.
58
- // See: https://github.com/getsentry/sentry-javascript/issues/6167
25
+ function captureReactException(error, { componentStack }, hint) {
59
26
  if (isAtLeastReact17(React.version) && browser.isError(error) && componentStack) {
60
27
  const errorBoundaryError = new Error(error.message);
61
28
  errorBoundaryError.name = `React ErrorBoundary ${error.name}`;
62
29
  errorBoundaryError.stack = componentStack;
63
-
64
- // Using the `LinkedErrors` integration to link the errors together.
65
30
  setCause(error, errorBoundaryError);
66
31
  }
67
-
68
- return browser$1.withScope(scope => {
69
- scope.setContext('react', { componentStack });
32
+ return browser$1.withScope((scope) => {
33
+ scope.setContext("react", { componentStack });
70
34
  return browser$1.captureException(error, hint);
71
35
  });
72
36
  }
73
-
74
- /**
75
- * Creates an error handler that can be used with the `onCaughtError`, `onUncaughtError`,
76
- * and `onRecoverableError` options in `createRoot` and `hydrateRoot` React DOM methods.
77
- *
78
- * @param callback An optional callback that will be called after the error is captured.
79
- * Use this to add custom handling for errors.
80
- *
81
- * @example
82
- *
83
- * ```JavaScript
84
- * const root = createRoot(container, {
85
- * onCaughtError: Sentry.reactErrorHandler(),
86
- * onUncaughtError: Sentry.reactErrorHandler((error, errorInfo) => {
87
- * console.warn('Caught error', error, errorInfo.componentStack);
88
- * });
89
- * });
90
- * ```
91
- */
92
- function reactErrorHandler(
93
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
- callback,
95
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
- ) {
97
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
+ function reactErrorHandler(callback) {
98
38
  return (error, errorInfo) => {
99
39
  const hasCallback = !!callback;
100
40
  const eventId = captureReactException(error, errorInfo, {
101
- mechanism: { handled: hasCallback, type: 'auto.function.react.error_handler' },
41
+ mechanism: { handled: hasCallback, type: "auto.function.react.error_handler" }
102
42
  });
103
43
  if (hasCallback) {
104
44
  callback(error, errorInfo, eventId);
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sources":["../../src/error.ts"],"sourcesContent":["import { captureException, withScope } from '@sentry/browser';\nimport { isError } from '@sentry/core/browser';\nimport type { ErrorInfo } from 'react';\nimport { version } from 'react';\n\n/**\n * See if React major version is 17+ by parsing version string.\n */\nexport function isAtLeastReact17(reactVersion: string): boolean {\n const reactMajor = reactVersion.match(/^([^.]+)/);\n return reactMajor !== null && parseInt(reactMajor[0]) >= 17;\n}\n\n/**\n * Recurse through `error.cause` chain to set cause on an error.\n */\nexport function setCause(error: Error & { cause?: Error }, cause: Error): void {\n const seenErrors = new WeakSet();\n\n function recurse(error: Error & { cause?: Error }, cause: Error): void {\n // If we've already seen the error, there is a recursive loop somewhere in the error's\n // cause chain. Let's just bail out then to prevent a stack overflow.\n if (seenErrors.has(error)) {\n return;\n }\n if (error.cause) {\n seenErrors.add(error);\n return recurse(error.cause, cause);\n }\n error.cause = cause;\n }\n\n recurse(error, cause);\n}\n\n/**\n * Captures an error that was thrown by a React ErrorBoundary or React root.\n *\n * @param error The error to capture.\n * @param errorInfo The errorInfo provided by React.\n * @param hint Optional additional data to attach to the Sentry event.\n * @returns the id of the captured Sentry event.\n */\nexport function captureReactException(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error: any,\n { componentStack }: ErrorInfo,\n hint?: Parameters<typeof captureException>[1],\n): string {\n // If on React version >= 17, create stack trace from componentStack param and links\n // to to the original error using `error.cause` otherwise relies on error param for stacktrace.\n // Linking errors requires the `LinkedErrors` integration be enabled.\n // See: https://reactjs.org/blog/2020/08/10/react-v17-rc.html#native-component-stacks\n //\n // Although `componentDidCatch` is typed to accept an `Error` object, it can also be invoked\n // with non-error objects. This is why we need to check if the error is an error-like object.\n // See: https://github.com/getsentry/sentry-javascript/issues/6167\n if (isAtLeastReact17(version) && isError(error) && componentStack) {\n const errorBoundaryError = new Error(error.message);\n errorBoundaryError.name = `React ErrorBoundary ${error.name}`;\n errorBoundaryError.stack = componentStack;\n\n // Using the `LinkedErrors` integration to link the errors together.\n setCause(error, errorBoundaryError);\n }\n\n return withScope(scope => {\n scope.setContext('react', { componentStack });\n return captureException(error, hint);\n });\n}\n\n/**\n * Creates an error handler that can be used with the `onCaughtError`, `onUncaughtError`,\n * and `onRecoverableError` options in `createRoot` and `hydrateRoot` React DOM methods.\n *\n * @param callback An optional callback that will be called after the error is captured.\n * Use this to add custom handling for errors.\n *\n * @example\n *\n * ```JavaScript\n * const root = createRoot(container, {\n * onCaughtError: Sentry.reactErrorHandler(),\n * onUncaughtError: Sentry.reactErrorHandler((error, errorInfo) => {\n * console.warn('Caught error', error, errorInfo.componentStack);\n * });\n * });\n * ```\n */\nexport function reactErrorHandler(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callback?: (error: any, errorInfo: ErrorInfo, eventId: string) => void,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): (error: any, errorInfo: ErrorInfo) => void {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (error: any, errorInfo: ErrorInfo) => {\n const hasCallback = !!callback;\n const eventId = captureReactException(error, errorInfo, {\n mechanism: { handled: hasCallback, type: 'auto.function.react.error_handler' },\n });\n if (hasCallback) {\n callback(error, errorInfo, eventId);\n }\n };\n}\n"],"names":["version","isError","withScope","captureException"],"mappings":";;;;;;AAKA;AACA;AACA;AACO,SAAS,gBAAgB,CAAC,YAAY,EAAmB;AAChE,EAAE,MAAM,aAAa,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC;AACnD,EAAE,OAAO,UAAA,KAAe,IAAA,IAAQ,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA,IAAK,EAAE;AAC7D;;AAEA;AACA;AACA;AACO,SAAS,QAAQ,CAAC,KAAK,EAA6B,KAAK,EAAe;AAC/E,EAAE,MAAM,UAAA,GAAa,IAAI,OAAO,EAAE;;AAElC,EAAE,SAAS,OAAO,CAAC,KAAK,EAA6B,KAAK,EAAe;AACzE;AACA;AACA,IAAI,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;AAC/B,MAAM;AACN,IAAI;AACJ,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE;AACrB,MAAM,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC;AAC3B,MAAM,OAAO,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC;AACxC,IAAI;AACJ,IAAI,KAAK,CAAC,KAAA,GAAQ,KAAK;AACvB,EAAE;;AAEF,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;AACvB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAA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"file":"error.js","sources":["../../src/error.ts"],"sourcesContent":["import { captureException, withScope } from '@sentry/browser';\nimport { isError } from '@sentry/core/browser';\nimport type { ErrorInfo } from 'react';\nimport { version } from 'react';\n\n/**\n * See if React major version is 17+ by parsing version string.\n */\nexport function isAtLeastReact17(reactVersion: string): boolean {\n const reactMajor = reactVersion.match(/^([^.]+)/);\n return reactMajor !== null && parseInt(reactMajor[0]) >= 17;\n}\n\n/**\n * Recurse through `error.cause` chain to set cause on an error.\n */\nexport function setCause(error: Error & { cause?: Error }, cause: Error): void {\n const seenErrors = new WeakSet();\n\n function recurse(error: Error & { cause?: Error }, cause: Error): void {\n // If we've already seen the error, there is a recursive loop somewhere in the error's\n // cause chain. Let's just bail out then to prevent a stack overflow.\n if (seenErrors.has(error)) {\n return;\n }\n if (error.cause) {\n seenErrors.add(error);\n return recurse(error.cause, cause);\n }\n error.cause = cause;\n }\n\n recurse(error, cause);\n}\n\n/**\n * Captures an error that was thrown by a React ErrorBoundary or React root.\n *\n * @param error The error to capture.\n * @param errorInfo The errorInfo provided by React.\n * @param hint Optional additional data to attach to the Sentry event.\n * @returns the id of the captured Sentry event.\n */\nexport function captureReactException(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error: any,\n { componentStack }: ErrorInfo,\n hint?: Parameters<typeof captureException>[1],\n): string {\n // If on React version >= 17, create stack trace from componentStack param and links\n // to to the original error using `error.cause` otherwise relies on error param for stacktrace.\n // Linking errors requires the `LinkedErrors` integration be enabled.\n // See: https://reactjs.org/blog/2020/08/10/react-v17-rc.html#native-component-stacks\n //\n // Although `componentDidCatch` is typed to accept an `Error` object, it can also be invoked\n // with non-error objects. This is why we need to check if the error is an error-like object.\n // See: https://github.com/getsentry/sentry-javascript/issues/6167\n if (isAtLeastReact17(version) && isError(error) && componentStack) {\n const errorBoundaryError = new Error(error.message);\n errorBoundaryError.name = `React ErrorBoundary ${error.name}`;\n errorBoundaryError.stack = componentStack;\n\n // Using the `LinkedErrors` integration to link the errors together.\n setCause(error, errorBoundaryError);\n }\n\n return withScope(scope => {\n scope.setContext('react', { componentStack });\n return captureException(error, hint);\n });\n}\n\n/**\n * Creates an error handler that can be used with the `onCaughtError`, `onUncaughtError`,\n * and `onRecoverableError` options in `createRoot` and `hydrateRoot` React DOM methods.\n *\n * @param callback An optional callback that will be called after the error is captured.\n * Use this to add custom handling for errors.\n *\n * @example\n *\n * ```JavaScript\n * const root = createRoot(container, {\n * onCaughtError: Sentry.reactErrorHandler(),\n * onUncaughtError: Sentry.reactErrorHandler((error, errorInfo) => {\n * console.warn('Caught error', error, errorInfo.componentStack);\n * });\n * });\n * ```\n */\nexport function reactErrorHandler(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callback?: (error: any, errorInfo: ErrorInfo, eventId: string) => void,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): (error: any, errorInfo: ErrorInfo) => void {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (error: any, errorInfo: ErrorInfo) => {\n const hasCallback = !!callback;\n const eventId = captureReactException(error, errorInfo, {\n mechanism: { handled: hasCallback, type: 'auto.function.react.error_handler' },\n });\n if (hasCallback) {\n callback(error, errorInfo, eventId);\n }\n };\n}\n"],"names":["error","cause","version","isError","withScope","captureException"],"mappings":";;;;;;AAQO,SAAS,iBAAiB,YAAA,EAA+B;AAC9D,EAAA,MAAM,UAAA,GAAa,YAAA,CAAa,KAAA,CAAM,UAAU,CAAA;AAChD,EAAA,OAAO,eAAe,IAAA,IAAQ,QAAA,CAAS,UAAA,CAAW,CAAC,CAAC,CAAA,IAAK,EAAA;AAC3D;AAKO,SAAS,QAAA,CAAS,OAAkC,KAAA,EAAoB;AAC7E,EAAA,MAAM,UAAA,uBAAiB,OAAA,EAAQ;AAE/B,EAAA,SAAS,OAAA,CAAQA,QAAkCC,MAAAA,EAAoB;AAGrE,IAAA,IAAI,UAAA,CAAW,GAAA,CAAID,MAAK,CAAA,EAAG;AACzB,MAAA;AAAA,IACF;AACA,IAAA,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AAAA,IACpC;AAAA,EACF,CAAA;AACF;;;;;;;"}
@@ -7,52 +7,38 @@ const debugBuild = require('./debug-build.js');
7
7
  const error = require('./error.js');
8
8
  const hoistNonReactStatics = require('./hoist-non-react-statics.js');
9
9
 
10
- const UNKNOWN_COMPONENT = 'unknown';
11
-
10
+ const UNKNOWN_COMPONENT = "unknown";
12
11
  const INITIAL_STATE = {
13
12
  componentStack: null,
14
13
  error: null,
15
- eventId: null,
14
+ eventId: null
16
15
  };
17
-
18
- /**
19
- * A ErrorBoundary component that logs errors to Sentry.
20
- * NOTE: If you are a Sentry user, and you are seeing this stack frame, it means the
21
- * Sentry React SDK ErrorBoundary caught an error invoking your application code. This
22
- * is expected behavior and NOT indicative of a bug with the Sentry React SDK.
23
- */
24
16
  class ErrorBoundary extends React.Component {
25
-
26
- constructor(props) {
17
+ constructor(props) {
27
18
  super(props);
28
-
29
19
  this.state = INITIAL_STATE;
30
20
  this._openFallbackReportDialog = true;
31
-
32
21
  const client = browser.getClient();
33
22
  if (client && props.showDialog) {
34
23
  this._openFallbackReportDialog = false;
35
- this._cleanupHook = client.on('afterSendEvent', event => {
24
+ this._cleanupHook = client.on("afterSendEvent", (event) => {
36
25
  if (!event.type && this._lastEventId && event.event_id === this._lastEventId) {
37
26
  browser.showReportDialog({ ...props.dialogOptions, eventId: this._lastEventId });
38
27
  }
39
28
  });
40
29
  }
41
30
  }
42
-
43
- componentDidCatch(error$1, errorInfo) {
31
+ componentDidCatch(error$1, errorInfo) {
44
32
  const { componentStack } = errorInfo;
45
33
  const { beforeCapture, onError, showDialog, dialogOptions } = this.props;
46
- browser.withScope(scope => {
34
+ browser.withScope((scope) => {
47
35
  if (beforeCapture) {
48
36
  beforeCapture(scope, error$1, componentStack);
49
37
  }
50
-
51
38
  const handled = this.props.handled != null ? this.props.handled : !!this.props.fallback;
52
39
  const eventId = error.captureReactException(error$1, errorInfo, {
53
- mechanism: { handled, type: 'auto.function.react.error_boundary' },
40
+ mechanism: { handled, type: "auto.function.react.error_boundary" }
54
41
  });
55
-
56
42
  if (onError) {
57
43
  onError(error$1, componentStack, eventId);
58
44
  }
@@ -62,104 +48,63 @@ class ErrorBoundary extends React.Component {
62
48
  browser.showReportDialog({ ...dialogOptions, eventId });
63
49
  }
64
50
  }
65
-
66
- // componentDidCatch is used over getDerivedStateFromError
67
- // so that componentStack is accessible through state.
68
51
  this.setState({ error: error$1, componentStack, eventId });
69
52
  });
70
53
  }
71
-
72
- componentDidMount() {
54
+ componentDidMount() {
73
55
  const { onMount } = this.props;
74
56
  if (onMount) {
75
57
  onMount();
76
58
  }
77
59
  }
78
-
79
- componentWillUnmount() {
60
+ componentWillUnmount() {
80
61
  const { error, componentStack, eventId } = this.state;
81
62
  const { onUnmount } = this.props;
82
63
  if (onUnmount) {
83
64
  if (this.state === INITIAL_STATE) {
84
- // If the error boundary never encountered an error, call onUnmount with null values
85
65
  onUnmount(null, null, null);
86
66
  } else {
87
- // `componentStack` and `eventId` are guaranteed to be non-null here because `onUnmount` is only called
88
- // when the error boundary has already encountered an error.
89
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
90
67
  onUnmount(error, componentStack, eventId);
91
68
  }
92
69
  }
93
-
94
70
  if (this._cleanupHook) {
95
71
  this._cleanupHook();
96
- this._cleanupHook = undefined;
72
+ this._cleanupHook = void 0;
97
73
  }
98
74
  }
99
-
100
- resetErrorBoundary() {
75
+ resetErrorBoundary() {
101
76
  const { onReset } = this.props;
102
77
  const { error, componentStack, eventId } = this.state;
103
78
  if (onReset) {
104
- // `componentStack` and `eventId` are guaranteed to be non-null here because `onReset` is only called
105
- // when the error boundary has already encountered an error.
106
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
107
79
  onReset(error, componentStack, eventId);
108
80
  }
109
81
  this.setState(INITIAL_STATE);
110
82
  }
111
-
112
- render() {
83
+ render() {
113
84
  const { fallback, children } = this.props;
114
85
  const state = this.state;
115
-
116
- // `componentStack` is only null in the initial state, when no error has been captured.
117
- // If an error has been captured, `componentStack` will be a string.
118
- // We cannot check `state.error` because null can be thrown as an error.
119
86
  if (state.componentStack === null) {
120
- return typeof children === 'function' ? children() : children;
87
+ return typeof children === "function" ? children() : children;
121
88
  }
122
-
123
- const element =
124
- typeof fallback === 'function'
125
- ? React.createElement(fallback, {
126
- error: state.error,
127
- componentStack: state.componentStack,
128
- resetError: () => this.resetErrorBoundary(),
129
- eventId: state.eventId,
130
- })
131
- : fallback;
132
-
89
+ const element = typeof fallback === "function" ? React.createElement(fallback, {
90
+ error: state.error,
91
+ componentStack: state.componentStack,
92
+ resetError: () => this.resetErrorBoundary(),
93
+ eventId: state.eventId
94
+ }) : fallback;
133
95
  if (React.isValidElement(element)) {
134
96
  return element;
135
97
  }
136
-
137
98
  if (fallback) {
138
- debugBuild.DEBUG_BUILD && core.debug.warn('fallback did not produce a valid ReactElement');
99
+ debugBuild.DEBUG_BUILD && core.debug.warn("fallback did not produce a valid ReactElement");
139
100
  }
140
-
141
- // Fail gracefully if no fallback provided or is not valid
142
101
  return null;
143
102
  }
144
103
  }
145
-
146
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
147
- function withErrorBoundary(
148
- WrappedComponent,
149
- errorBoundaryOptions,
150
- ) {
104
+ function withErrorBoundary(WrappedComponent, errorBoundaryOptions) {
151
105
  const componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;
152
-
153
- const Wrapped = React.memo((props) => (
154
- React.createElement(ErrorBoundary, { ...errorBoundaryOptions,}
155
- , React.createElement(WrappedComponent, { ...props,} )
156
- )
157
- )) ;
158
-
106
+ const Wrapped = React.memo((props) => /* @__PURE__ */ React.createElement(ErrorBoundary, { ...errorBoundaryOptions }, /* @__PURE__ */ React.createElement(WrappedComponent, { ...props })));
159
107
  Wrapped.displayName = `errorBoundary(${componentDisplayName})`;
160
-
161
- // Copy over static methods from Wrapped component to Profiler HOC
162
- // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over
163
108
  hoistNonReactStatics.hoistNonReactStatics(Wrapped, WrappedComponent);
164
109
  return Wrapped;
165
110
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errorboundary.js","sources":["../../src/errorboundary.tsx"],"sourcesContent":["import type { ReportDialogOptions } from '@sentry/browser';\nimport { getClient, showReportDialog, withScope } from '@sentry/browser';\nimport type { Scope } from '@sentry/core';\nimport { debug } from '@sentry/core';\nimport * as React from 'react';\nimport { DEBUG_BUILD } from './debug-build';\nimport { captureReactException } from './error';\nimport { hoistNonReactStatics } from './hoist-non-react-statics';\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type FallbackRender = (errorData: {\n error: unknown;\n componentStack: string;\n eventId: string;\n resetError(): void;\n}) => React.ReactElement;\n\ntype OnUnmountType = {\n (error: null, componentStack: null, eventId: null): void;\n (error: unknown, componentStack: string, eventId: string): void;\n};\n\nexport type ErrorBoundaryProps = {\n children?: React.ReactNode | (() => React.ReactNode);\n /** If a Sentry report dialog should be rendered on error */\n showDialog?: boolean | undefined;\n /**\n * Options to be passed into the Sentry report dialog.\n * No-op if {@link showDialog} is false.\n */\n dialogOptions?: ReportDialogOptions | undefined;\n /**\n * A fallback component that gets rendered when the error boundary encounters an error.\n *\n * Can either provide a React Component, or a function that returns React Component as\n * a valid fallback prop. If a function is provided, the function will be called with\n * the error, the component stack, and an function that resets the error boundary on error.\n *\n */\n fallback?: React.ReactElement | FallbackRender | undefined;\n /**\n * If set to `true` or `false`, the error `handled` property will be set to the given value.\n * If unset, the default behaviour is to rely on the presence of the `fallback` prop to determine\n * if the error was handled or not.\n */\n handled?: boolean | undefined;\n /** Called when the error boundary encounters an error */\n onError?: ((error: unknown, componentStack: string, eventId: string) => void) | undefined;\n /** Called on componentDidMount() */\n onMount?: (() => void) | undefined;\n /**\n * Called when the error boundary resets due to a reset call from the\n * fallback render props function.\n */\n onReset?: ((error: unknown, componentStack: string, eventId: string) => void) | undefined;\n /**\n * Called on componentWillUnmount() with the error, componentStack, and eventId.\n *\n * If the error boundary never encountered an error, the error\n * componentStack, and eventId will be null.\n */\n onUnmount?: OnUnmountType | undefined;\n /** Called before the error is captured by Sentry, allows for you to add tags or context using the scope */\n beforeCapture?: ((scope: Scope, error: unknown, componentStack: string) => void) | undefined;\n};\n\ntype ErrorBoundaryState =\n | {\n componentStack: null;\n error: null;\n eventId: null;\n }\n | {\n componentStack: React.ErrorInfo['componentStack'];\n error: unknown;\n eventId: string;\n };\n\nconst INITIAL_STATE: ErrorBoundaryState = {\n componentStack: null,\n error: null,\n eventId: null,\n};\n\n/**\n * A ErrorBoundary component that logs errors to Sentry.\n * NOTE: If you are a Sentry user, and you are seeing this stack frame, it means the\n * Sentry React SDK ErrorBoundary caught an error invoking your application code. This\n * is expected behavior and NOT indicative of a bug with the Sentry React SDK.\n */\nclass ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {\n public state: ErrorBoundaryState;\n\n private readonly _openFallbackReportDialog: boolean;\n\n private _lastEventId?: string;\n private _cleanupHook?: () => void;\n\n public constructor(props: ErrorBoundaryProps) {\n super(props);\n\n this.state = INITIAL_STATE;\n this._openFallbackReportDialog = true;\n\n const client = getClient();\n if (client && props.showDialog) {\n this._openFallbackReportDialog = false;\n this._cleanupHook = client.on('afterSendEvent', event => {\n if (!event.type && this._lastEventId && event.event_id === this._lastEventId) {\n showReportDialog({ ...props.dialogOptions, eventId: this._lastEventId });\n }\n });\n }\n }\n\n public componentDidCatch(error: unknown, errorInfo: React.ErrorInfo): void {\n const { componentStack } = errorInfo;\n const { beforeCapture, onError, showDialog, dialogOptions } = this.props;\n withScope(scope => {\n if (beforeCapture) {\n beforeCapture(scope, error, componentStack);\n }\n\n const handled = this.props.handled != null ? this.props.handled : !!this.props.fallback;\n const eventId = captureReactException(error, errorInfo, {\n mechanism: { handled, type: 'auto.function.react.error_boundary' },\n });\n\n if (onError) {\n onError(error, componentStack, eventId);\n }\n if (showDialog) {\n this._lastEventId = eventId;\n if (this._openFallbackReportDialog) {\n showReportDialog({ ...dialogOptions, eventId });\n }\n }\n\n // componentDidCatch is used over getDerivedStateFromError\n // so that componentStack is accessible through state.\n this.setState({ error, componentStack, eventId });\n });\n }\n\n public componentDidMount(): void {\n const { onMount } = this.props;\n if (onMount) {\n onMount();\n }\n }\n\n public componentWillUnmount(): void {\n const { error, componentStack, eventId } = this.state;\n const { onUnmount } = this.props;\n if (onUnmount) {\n if (this.state === INITIAL_STATE) {\n // If the error boundary never encountered an error, call onUnmount with null values\n onUnmount(null, null, null);\n } else {\n // `componentStack` and `eventId` are guaranteed to be non-null here because `onUnmount` is only called\n // when the error boundary has already encountered an error.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n onUnmount(error, componentStack!, eventId!);\n }\n }\n\n if (this._cleanupHook) {\n this._cleanupHook();\n this._cleanupHook = undefined;\n }\n }\n\n public resetErrorBoundary(): void {\n const { onReset } = this.props;\n const { error, componentStack, eventId } = this.state;\n if (onReset) {\n // `componentStack` and `eventId` are guaranteed to be non-null here because `onReset` is only called\n // when the error boundary has already encountered an error.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n onReset(error, componentStack!, eventId!);\n }\n this.setState(INITIAL_STATE);\n }\n\n public render(): React.ReactNode {\n const { fallback, children } = this.props;\n const state = this.state;\n\n // `componentStack` is only null in the initial state, when no error has been captured.\n // If an error has been captured, `componentStack` will be a string.\n // We cannot check `state.error` because null can be thrown as an error.\n if (state.componentStack === null) {\n return typeof children === 'function' ? children() : children;\n }\n\n const element =\n typeof fallback === 'function'\n ? React.createElement(fallback, {\n error: state.error,\n componentStack: state.componentStack,\n resetError: () => this.resetErrorBoundary(),\n eventId: state.eventId,\n })\n : fallback;\n\n if (React.isValidElement(element)) {\n return element;\n }\n\n if (fallback) {\n DEBUG_BUILD && debug.warn('fallback did not produce a valid ReactElement');\n }\n\n // Fail gracefully if no fallback provided or is not valid\n return null;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction withErrorBoundary<P extends Record<string, any>>(\n WrappedComponent: React.ComponentType<P>,\n errorBoundaryOptions: ErrorBoundaryProps,\n): React.FC<P> {\n const componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;\n\n const Wrapped = React.memo((props: P) => (\n <ErrorBoundary {...errorBoundaryOptions}>\n <WrappedComponent {...props} />\n </ErrorBoundary>\n )) as unknown as React.FC<P>;\n\n Wrapped.displayName = `errorBoundary(${componentDisplayName})`;\n\n // Copy over static methods from Wrapped component to Profiler HOC\n // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over\n hoistNonReactStatics(Wrapped, WrappedComponent);\n return Wrapped;\n}\n\nexport { ErrorBoundary, withErrorBoundary };\n"],"names":["getClient","showReportDialog","error","withScope","captureReactException","DEBUG_BUILD","debug","hoistNonReactStatics"],"mappings":";;;;;;;;;AASO,MAAM,iBAAA,GAAoB;;AAsEjC,MAAM,aAAa,GAAuB;AAC1C,EAAE,cAAc,EAAE,IAAI;AACtB,EAAE,KAAK,EAAE,IAAI;AACb,EAAE,OAAO,EAAE,IAAI;AACf,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,aAAA,SAAsB,KAAK,CAAC,SAAS,CAAyC;;AAQpF,GAAS,WAAW,CAAC,KAAK,EAAsB;AAChD,IAAI,KAAK,CAAC,KAAK,CAAC;;AAEhB,IAAI,IAAI,CAAC,KAAA,GAAQ,aAAa;AAC9B,IAAI,IAAI,CAAC,yBAAA,GAA4B,IAAI;;AAEzC,IAAI,MAAM,MAAA,GAASA,iBAAS,EAAE;AAC9B,IAAI,IAAI,MAAA,IAAU,KAAK,CAAC,UAAU,EAAE;AACpC,MAAM,IAAI,CAAC,yBAAA,GAA4B,KAAK;AAC5C,MAAM,IAAI,CAAC,YAAA,GAAe,MAAM,CAAC,EAAE,CAAC,gBAAgB,EAAE,KAAA,IAAS;AAC/D,QAAQ,IAAI,CAAC,KAAK,CAAC,IAAA,IAAQ,IAAI,CAAC,YAAA,IAAgB,K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AAc,CAAC,cAAc,EAAE,oBAAoB,CAAC,CAAC,CAAC;;AAEhE;AACA;AACA,EAAEC,yCAAoB,CAAC,OAAO,EAAE,gBAAgB,CAAC;AACjD,EAAE,OAAO,OAAO;AAChB;;;;;;"}
1
+ {"version":3,"file":"errorboundary.js","sources":["../../src/errorboundary.tsx"],"sourcesContent":["import type { ReportDialogOptions } from '@sentry/browser';\nimport { getClient, showReportDialog, withScope } from '@sentry/browser';\nimport type { Scope } from '@sentry/core';\nimport { debug } from '@sentry/core';\nimport * as React from 'react';\nimport { DEBUG_BUILD } from './debug-build';\nimport { captureReactException } from './error';\nimport { hoistNonReactStatics } from './hoist-non-react-statics';\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type FallbackRender = (errorData: {\n error: unknown;\n componentStack: string;\n eventId: string;\n resetError(): void;\n}) => React.ReactElement;\n\ntype OnUnmountType = {\n (error: null, componentStack: null, eventId: null): void;\n (error: unknown, componentStack: string, eventId: string): void;\n};\n\nexport type ErrorBoundaryProps = {\n children?: React.ReactNode | (() => React.ReactNode);\n /** If a Sentry report dialog should be rendered on error */\n showDialog?: boolean | undefined;\n /**\n * Options to be passed into the Sentry report dialog.\n * No-op if {@link showDialog} is false.\n */\n dialogOptions?: ReportDialogOptions | undefined;\n /**\n * A fallback component that gets rendered when the error boundary encounters an error.\n *\n * Can either provide a React Component, or a function that returns React Component as\n * a valid fallback prop. If a function is provided, the function will be called with\n * the error, the component stack, and an function that resets the error boundary on error.\n *\n */\n fallback?: React.ReactElement | FallbackRender | undefined;\n /**\n * If set to `true` or `false`, the error `handled` property will be set to the given value.\n * If unset, the default behaviour is to rely on the presence of the `fallback` prop to determine\n * if the error was handled or not.\n */\n handled?: boolean | undefined;\n /** Called when the error boundary encounters an error */\n onError?: ((error: unknown, componentStack: string, eventId: string) => void) | undefined;\n /** Called on componentDidMount() */\n onMount?: (() => void) | undefined;\n /**\n * Called when the error boundary resets due to a reset call from the\n * fallback render props function.\n */\n onReset?: ((error: unknown, componentStack: string, eventId: string) => void) | undefined;\n /**\n * Called on componentWillUnmount() with the error, componentStack, and eventId.\n *\n * If the error boundary never encountered an error, the error\n * componentStack, and eventId will be null.\n */\n onUnmount?: OnUnmountType | undefined;\n /** Called before the error is captured by Sentry, allows for you to add tags or context using the scope */\n beforeCapture?: ((scope: Scope, error: unknown, componentStack: string) => void) | undefined;\n};\n\ntype ErrorBoundaryState =\n | {\n componentStack: null;\n error: null;\n eventId: null;\n }\n | {\n componentStack: React.ErrorInfo['componentStack'];\n error: unknown;\n eventId: string;\n };\n\nconst INITIAL_STATE: ErrorBoundaryState = {\n componentStack: null,\n error: null,\n eventId: null,\n};\n\n/**\n * A ErrorBoundary component that logs errors to Sentry.\n * NOTE: If you are a Sentry user, and you are seeing this stack frame, it means the\n * Sentry React SDK ErrorBoundary caught an error invoking your application code. This\n * is expected behavior and NOT indicative of a bug with the Sentry React SDK.\n */\nclass ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {\n public state: ErrorBoundaryState;\n\n private readonly _openFallbackReportDialog: boolean;\n\n private _lastEventId?: string;\n private _cleanupHook?: () => void;\n\n public constructor(props: ErrorBoundaryProps) {\n super(props);\n\n this.state = INITIAL_STATE;\n this._openFallbackReportDialog = true;\n\n const client = getClient();\n if (client && props.showDialog) {\n this._openFallbackReportDialog = false;\n this._cleanupHook = client.on('afterSendEvent', event => {\n if (!event.type && this._lastEventId && event.event_id === this._lastEventId) {\n showReportDialog({ ...props.dialogOptions, eventId: this._lastEventId });\n }\n });\n }\n }\n\n public componentDidCatch(error: unknown, errorInfo: React.ErrorInfo): void {\n const { componentStack } = errorInfo;\n const { beforeCapture, onError, showDialog, dialogOptions } = this.props;\n withScope(scope => {\n if (beforeCapture) {\n beforeCapture(scope, error, componentStack);\n }\n\n const handled = this.props.handled != null ? this.props.handled : !!this.props.fallback;\n const eventId = captureReactException(error, errorInfo, {\n mechanism: { handled, type: 'auto.function.react.error_boundary' },\n });\n\n if (onError) {\n onError(error, componentStack, eventId);\n }\n if (showDialog) {\n this._lastEventId = eventId;\n if (this._openFallbackReportDialog) {\n showReportDialog({ ...dialogOptions, eventId });\n }\n }\n\n // componentDidCatch is used over getDerivedStateFromError\n // so that componentStack is accessible through state.\n this.setState({ error, componentStack, eventId });\n });\n }\n\n public componentDidMount(): void {\n const { onMount } = this.props;\n if (onMount) {\n onMount();\n }\n }\n\n public componentWillUnmount(): void {\n const { error, componentStack, eventId } = this.state;\n const { onUnmount } = this.props;\n if (onUnmount) {\n if (this.state === INITIAL_STATE) {\n // If the error boundary never encountered an error, call onUnmount with null values\n onUnmount(null, null, null);\n } else {\n // `componentStack` and `eventId` are guaranteed to be non-null here because `onUnmount` is only called\n // when the error boundary has already encountered an error.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n onUnmount(error, componentStack!, eventId!);\n }\n }\n\n if (this._cleanupHook) {\n this._cleanupHook();\n this._cleanupHook = undefined;\n }\n }\n\n public resetErrorBoundary(): void {\n const { onReset } = this.props;\n const { error, componentStack, eventId } = this.state;\n if (onReset) {\n // `componentStack` and `eventId` are guaranteed to be non-null here because `onReset` is only called\n // when the error boundary has already encountered an error.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n onReset(error, componentStack!, eventId!);\n }\n this.setState(INITIAL_STATE);\n }\n\n public render(): React.ReactNode {\n const { fallback, children } = this.props;\n const state = this.state;\n\n // `componentStack` is only null in the initial state, when no error has been captured.\n // If an error has been captured, `componentStack` will be a string.\n // We cannot check `state.error` because null can be thrown as an error.\n if (state.componentStack === null) {\n return typeof children === 'function' ? children() : children;\n }\n\n const element =\n typeof fallback === 'function'\n ? React.createElement(fallback, {\n error: state.error,\n componentStack: state.componentStack,\n resetError: () => this.resetErrorBoundary(),\n eventId: state.eventId,\n })\n : fallback;\n\n if (React.isValidElement(element)) {\n return element;\n }\n\n if (fallback) {\n DEBUG_BUILD && debug.warn('fallback did not produce a valid ReactElement');\n }\n\n // Fail gracefully if no fallback provided or is not valid\n return null;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction withErrorBoundary<P extends Record<string, any>>(\n WrappedComponent: React.ComponentType<P>,\n errorBoundaryOptions: ErrorBoundaryProps,\n): React.FC<P> {\n const componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;\n\n const Wrapped = React.memo((props: P) => (\n <ErrorBoundary {...errorBoundaryOptions}>\n <WrappedComponent {...props} />\n </ErrorBoundary>\n )) as unknown as React.FC<P>;\n\n Wrapped.displayName = `errorBoundary(${componentDisplayName})`;\n\n // Copy over static methods from Wrapped component to Profiler HOC\n // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over\n hoistNonReactStatics(Wrapped, WrappedComponent);\n return Wrapped;\n}\n\nexport { ErrorBoundary, withErrorBoundary };\n"],"names":["getClient","showReportDialog","error","withScope","captureReactException","DEBUG_BUILD","debug","hoistNonReactStatics"],"mappings":";;;;;;;;;AASO,MAAM,iBAAA,GAAoB;AAsEjC,MAAM,aAAA,GAAoC;AAAA,EACxC,cAAA,EAAgB,IAAA;AAAA,EAChB,KAAA,EAAO,IAAA;AAAA,EACP,OAAA,EAAS;AACX,CAAA;AAQA,MAAM,aAAA,SAAsB,MAAM,SAAA,CAAkD;AAAA,EAQ3E,YAAY,KAAA,EAA2B;AAC5C,IAAA,KAAA,CAAM,KAAK,CAAA;AAEX,IAAA,IAAA,CAAK,KAAA,GAAQ,aAAA;AACb,IAAA,IAAA,CAAK,yBAAA,GAA4B,IAAA;AAEjC,IAAA,MAAM,SAASA,iBAAA,EAAU;AACzB,IAAA,IAAI,MAAA,IAAU,MAAM,UAAA,EAAY;AAC9B,MAAA,IAAA,CAAK,yBAAA,GAA4B,KAAA;AACjC,MAAA,IAAA,CAAK,YAAA,GAAe,MAAA,CAAO,EAAA,CAAG,gBAAA,EAAkB,CAAA,KAAA,KAAS;AACvD,QAAA,IAAI,CAAC,MAAM,IAAA,IAAQ,IAAA,CAAK,gB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
  const REACT_STATICS = {
7
4
  childContextTypes: true,
8
5
  contextType: true,
@@ -14,12 +11,8 @@ const REACT_STATICS = {
14
11
  getDerivedStateFromProps: true,
15
12
  mixins: true,
16
13
  propTypes: true,
17
- type: true,
18
- } ;
19
-
20
- /**
21
- * Known JavaScript function statics that should not be hoisted
22
- */
14
+ type: true
15
+ };
23
16
  const KNOWN_STATICS = {
24
17
  name: true,
25
18
  length: true,
@@ -27,131 +20,70 @@ const KNOWN_STATICS = {
27
20
  caller: true,
28
21
  callee: true,
29
22
  arguments: true,
30
- arity: true,
31
- } ;
32
-
33
- /**
34
- * Statics specific to ForwardRef components
35
- */
23
+ arity: true
24
+ };
36
25
  const FORWARD_REF_STATICS = {
37
26
  $$typeof: true,
38
27
  render: true,
39
28
  defaultProps: true,
40
29
  displayName: true,
41
- propTypes: true,
42
- } ;
43
-
44
- /**
45
- * Statics specific to Memo components
46
- */
30
+ propTypes: true
31
+ };
47
32
  const MEMO_STATICS = {
48
33
  $$typeof: true,
49
34
  compare: true,
50
35
  defaultProps: true,
51
36
  displayName: true,
52
37
  propTypes: true,
53
- type: true,
54
- } ;
55
-
56
- /**
57
- * Inlined react-is utilities
58
- * We only need to detect ForwardRef and Memo types
59
- */
60
- const ForwardRefType = Symbol.for('react.forward_ref');
61
- const MemoType = Symbol.for('react.memo');
62
-
63
- /**
64
- * Check if a component is a Memo component
65
- */
38
+ type: true
39
+ };
40
+ const ForwardRefType = /* @__PURE__ */ Symbol.for("react.forward_ref");
41
+ const MemoType = /* @__PURE__ */ Symbol.for("react.memo");
66
42
  function isMemo(component) {
67
- return (
68
- typeof component === 'object' && component !== null && (component ).$$typeof === MemoType
69
- );
43
+ return typeof component === "object" && component !== null && component.$$typeof === MemoType;
70
44
  }
71
-
72
- /**
73
- * Map of React component types to their specific statics
74
- */
75
45
  const TYPE_STATICS = {};
76
46
  TYPE_STATICS[ForwardRefType] = FORWARD_REF_STATICS;
77
47
  TYPE_STATICS[MemoType] = MEMO_STATICS;
78
-
79
- /**
80
- * Get the appropriate statics object for a given component
81
- */
82
48
  function getStatics(component) {
83
- // React v16.11 and below
84
49
  if (isMemo(component)) {
85
50
  return MEMO_STATICS;
86
51
  }
87
-
88
- // React v16.12 and above
89
- const componentType = (component ).$$typeof;
90
- return (componentType && TYPE_STATICS[componentType]) || REACT_STATICS;
52
+ const componentType = component.$$typeof;
53
+ return componentType && TYPE_STATICS[componentType] || REACT_STATICS;
91
54
  }
92
-
93
55
  const defineProperty = Object.defineProperty.bind(Object);
94
56
  const getOwnPropertyNames = Object.getOwnPropertyNames.bind(Object);
95
57
  const getOwnPropertySymbols = Object.getOwnPropertySymbols?.bind(Object);
96
58
  const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor.bind(Object);
97
59
  const getPrototypeOf = Object.getPrototypeOf.bind(Object);
98
60
  const objectPrototype = Object.prototype;
99
-
100
- /**
101
- * Copies non-react specific statics from a child component to a parent component.
102
- * Similar to Object.assign, but copies all static properties from source to target,
103
- * excluding React-specific statics and known JavaScript statics.
104
- *
105
- * @param targetComponent - The component to copy statics to
106
- * @param sourceComponent - The component to copy statics from
107
- * @param excludelist - An optional object of keys to exclude from hoisting
108
- * @returns The target component with hoisted statics
109
- */
110
- function hoistNonReactStatics
111
-
112
- (targetComponent, sourceComponent, excludelist) {
113
- if (typeof sourceComponent !== 'string') {
114
- // Don't hoist over string (html) components
61
+ function hoistNonReactStatics(targetComponent, sourceComponent, excludelist) {
62
+ if (typeof sourceComponent !== "string") {
115
63
  if (objectPrototype) {
116
64
  const inheritedComponent = getPrototypeOf(sourceComponent);
117
-
118
65
  if (inheritedComponent && inheritedComponent !== objectPrototype) {
119
66
  hoistNonReactStatics(targetComponent, inheritedComponent);
120
67
  }
121
68
  }
122
-
123
69
  let keys = getOwnPropertyNames(sourceComponent);
124
-
125
70
  if (getOwnPropertySymbols) {
126
71
  keys = keys.concat(getOwnPropertySymbols(sourceComponent));
127
72
  }
128
-
129
73
  const targetStatics = getStatics(targetComponent);
130
74
  const sourceStatics = getStatics(sourceComponent);
131
-
132
75
  for (const key of keys) {
133
- // Use key directly - String(key) throws for Symbols if minified to '' + key (#18966)
134
- if (
135
- !KNOWN_STATICS[key ] &&
136
- true &&
137
- !sourceStatics?.[key ] &&
138
- !targetStatics?.[key ] &&
139
- !getOwnPropertyDescriptor(targetComponent, key) // Don't overwrite existing properties
140
- ) {
76
+ if (!KNOWN_STATICS[key] && true && !sourceStatics?.[key] && !targetStatics?.[key] && !getOwnPropertyDescriptor(targetComponent, key)) {
141
77
  const descriptor = getOwnPropertyDescriptor(sourceComponent, key);
142
-
143
78
  if (descriptor) {
144
79
  try {
145
- // Avoid failures from read-only properties
146
80
  defineProperty(targetComponent, key, descriptor);
147
81
  } catch (_e) {
148
- // Silently ignore errors
149
82
  }
150
83
  }
151
84
  }
152
85
  }
153
86
  }
154
-
155
87
  return targetComponent;
156
88
  }
157
89