@depup/sentry__react 10.44.0-depup.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 (140) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -0
  3. package/build/cjs/constants.js +12 -0
  4. package/build/cjs/constants.js.map +1 -0
  5. package/build/cjs/debug-build.js +11 -0
  6. package/build/cjs/debug-build.js.map +1 -0
  7. package/build/cjs/error.js +113 -0
  8. package/build/cjs/error.js.map +1 -0
  9. package/build/cjs/errorboundary.js +170 -0
  10. package/build/cjs/errorboundary.js.map +1 -0
  11. package/build/cjs/hoist-non-react-statics.js +159 -0
  12. package/build/cjs/hoist-non-react-statics.js.map +1 -0
  13. package/build/cjs/index.js +51 -0
  14. package/build/cjs/index.js.map +1 -0
  15. package/build/cjs/profiler.js +226 -0
  16. package/build/cjs/profiler.js.map +1 -0
  17. package/build/cjs/reactrouter-compat-utils/instrumentation.js +1295 -0
  18. package/build/cjs/reactrouter-compat-utils/instrumentation.js.map +1 -0
  19. package/build/cjs/reactrouter-compat-utils/lazy-routes.js +160 -0
  20. package/build/cjs/reactrouter-compat-utils/lazy-routes.js.map +1 -0
  21. package/build/cjs/reactrouter-compat-utils/route-manifest.js +194 -0
  22. package/build/cjs/reactrouter-compat-utils/route-manifest.js.map +1 -0
  23. package/build/cjs/reactrouter-compat-utils/utils.js +336 -0
  24. package/build/cjs/reactrouter-compat-utils/utils.js.map +1 -0
  25. package/build/cjs/reactrouter.js +236 -0
  26. package/build/cjs/reactrouter.js.map +1 -0
  27. package/build/cjs/reactrouterv3.js +130 -0
  28. package/build/cjs/reactrouterv3.js.map +1 -0
  29. package/build/cjs/reactrouterv6.js +61 -0
  30. package/build/cjs/reactrouterv6.js.map +1 -0
  31. package/build/cjs/reactrouterv7.js +61 -0
  32. package/build/cjs/reactrouterv7.js.map +1 -0
  33. package/build/cjs/redux.js +106 -0
  34. package/build/cjs/redux.js.map +1 -0
  35. package/build/cjs/sdk.js +21 -0
  36. package/build/cjs/sdk.js.map +1 -0
  37. package/build/cjs/tanstackrouter.js +134 -0
  38. package/build/cjs/tanstackrouter.js.map +1 -0
  39. package/build/esm/constants.js +8 -0
  40. package/build/esm/constants.js.map +1 -0
  41. package/build/esm/debug-build.js +9 -0
  42. package/build/esm/debug-build.js.map +1 -0
  43. package/build/esm/error.js +108 -0
  44. package/build/esm/error.js.map +1 -0
  45. package/build/esm/errorboundary.js +166 -0
  46. package/build/esm/errorboundary.js.map +1 -0
  47. package/build/esm/hoist-non-react-statics.js +157 -0
  48. package/build/esm/hoist-non-react-statics.js.map +1 -0
  49. package/build/esm/index.js +12 -0
  50. package/build/esm/index.js.map +1 -0
  51. package/build/esm/package.json +1 -0
  52. package/build/esm/profiler.js +221 -0
  53. package/build/esm/profiler.js.map +1 -0
  54. package/build/esm/reactrouter-compat-utils/instrumentation.js +1281 -0
  55. package/build/esm/reactrouter-compat-utils/instrumentation.js.map +1 -0
  56. package/build/esm/reactrouter-compat-utils/lazy-routes.js +156 -0
  57. package/build/esm/reactrouter-compat-utils/lazy-routes.js.map +1 -0
  58. package/build/esm/reactrouter-compat-utils/route-manifest.js +191 -0
  59. package/build/esm/reactrouter-compat-utils/route-manifest.js.map +1 -0
  60. package/build/esm/reactrouter-compat-utils/utils.js +320 -0
  61. package/build/esm/reactrouter-compat-utils/utils.js.map +1 -0
  62. package/build/esm/reactrouter.js +232 -0
  63. package/build/esm/reactrouter.js.map +1 -0
  64. package/build/esm/reactrouterv3.js +128 -0
  65. package/build/esm/reactrouterv3.js.map +1 -0
  66. package/build/esm/reactrouterv6.js +55 -0
  67. package/build/esm/reactrouterv6.js.map +1 -0
  68. package/build/esm/reactrouterv7.js +55 -0
  69. package/build/esm/reactrouterv7.js.map +1 -0
  70. package/build/esm/redux.js +104 -0
  71. package/build/esm/redux.js.map +1 -0
  72. package/build/esm/sdk.js +19 -0
  73. package/build/esm/sdk.js.map +1 -0
  74. package/build/esm/tanstackrouter.js +132 -0
  75. package/build/esm/tanstackrouter.js.map +1 -0
  76. package/build/types/constants.d.ts +4 -0
  77. package/build/types/constants.d.ts.map +1 -0
  78. package/build/types/debug-build.d.ts +7 -0
  79. package/build/types/debug-build.d.ts.map +1 -0
  80. package/build/types/error.d.ts +41 -0
  81. package/build/types/error.d.ts.map +1 -0
  82. package/build/types/errorboundary.d.ts +87 -0
  83. package/build/types/errorboundary.d.ts.map +1 -0
  84. package/build/types/hoist-non-react-statics.d.ts +21 -0
  85. package/build/types/hoist-non-react-statics.d.ts.map +1 -0
  86. package/build/types/index.d.ts +13 -0
  87. package/build/types/index.d.ts.map +1 -0
  88. package/build/types/profiler.d.ts +56 -0
  89. package/build/types/profiler.d.ts.map +1 -0
  90. package/build/types/reactrouter-compat-utils/index.d.ts +5 -0
  91. package/build/types/reactrouter-compat-utils/index.d.ts.map +1 -0
  92. package/build/types/reactrouter-compat-utils/instrumentation.d.ts +117 -0
  93. package/build/types/reactrouter-compat-utils/instrumentation.d.ts.map +1 -0
  94. package/build/types/reactrouter-compat-utils/lazy-routes.d.ts +18 -0
  95. package/build/types/reactrouter-compat-utils/lazy-routes.d.ts.map +1 -0
  96. package/build/types/reactrouter-compat-utils/route-manifest.d.ts +13 -0
  97. package/build/types/reactrouter-compat-utils/route-manifest.d.ts.map +1 -0
  98. package/build/types/reactrouter-compat-utils/utils.d.ts +71 -0
  99. package/build/types/reactrouter-compat-utils/utils.d.ts.map +1 -0
  100. package/build/types/reactrouter.d.ts +41 -0
  101. package/build/types/reactrouter.d.ts.map +1 -0
  102. package/build/types/reactrouterv3.d.ts +29 -0
  103. package/build/types/reactrouterv3.d.ts.map +1 -0
  104. package/build/types/reactrouterv6.d.ts +32 -0
  105. package/build/types/reactrouterv6.d.ts.map +1 -0
  106. package/build/types/reactrouterv7.d.ts +32 -0
  107. package/build/types/reactrouterv7.d.ts.map +1 -0
  108. package/build/types/redux.d.ts +38 -0
  109. package/build/types/redux.d.ts.map +1 -0
  110. package/build/types/sdk.d.ts +7 -0
  111. package/build/types/sdk.d.ts.map +1 -0
  112. package/build/types/tanstackrouter.d.ts +13 -0
  113. package/build/types/tanstackrouter.d.ts.map +1 -0
  114. package/build/types/types.d.ts +163 -0
  115. package/build/types/types.d.ts.map +1 -0
  116. package/build/types/vendor/tanstackrouter-types.d.ts +36 -0
  117. package/build/types/vendor/tanstackrouter-types.d.ts.map +1 -0
  118. package/build/types-ts3.8/constants.d.ts +4 -0
  119. package/build/types-ts3.8/debug-build.d.ts +7 -0
  120. package/build/types-ts3.8/error.d.ts +41 -0
  121. package/build/types-ts3.8/errorboundary.d.ts +87 -0
  122. package/build/types-ts3.8/hoist-non-react-statics.d.ts +21 -0
  123. package/build/types-ts3.8/index.d.ts +13 -0
  124. package/build/types-ts3.8/profiler.d.ts +56 -0
  125. package/build/types-ts3.8/reactrouter-compat-utils/index.d.ts +5 -0
  126. package/build/types-ts3.8/reactrouter-compat-utils/instrumentation.d.ts +117 -0
  127. package/build/types-ts3.8/reactrouter-compat-utils/lazy-routes.d.ts +18 -0
  128. package/build/types-ts3.8/reactrouter-compat-utils/route-manifest.d.ts +13 -0
  129. package/build/types-ts3.8/reactrouter-compat-utils/utils.d.ts +77 -0
  130. package/build/types-ts3.8/reactrouter.d.ts +41 -0
  131. package/build/types-ts3.8/reactrouterv3.d.ts +29 -0
  132. package/build/types-ts3.8/reactrouterv6.d.ts +32 -0
  133. package/build/types-ts3.8/reactrouterv7.d.ts +32 -0
  134. package/build/types-ts3.8/redux.d.ts +38 -0
  135. package/build/types-ts3.8/sdk.d.ts +7 -0
  136. package/build/types-ts3.8/tanstackrouter.d.ts +13 -0
  137. package/build/types-ts3.8/types.d.ts +163 -0
  138. package/build/types-ts3.8/vendor/tanstackrouter-types.d.ts +36 -0
  139. package/changes.json +5 -0
  140. package/package.json +108 -0
@@ -0,0 +1,108 @@
1
+ import { withScope, captureException } from '@sentry/browser';
2
+ import { isError } from '@sentry/core';
3
+ import { version } from 'react';
4
+
5
+ /**
6
+ * See if React major version is 17+ by parsing version string.
7
+ */
8
+ function isAtLeastReact17(reactVersion) {
9
+ const reactMajor = reactVersion.match(/^([^.]+)/);
10
+ return reactMajor !== null && parseInt(reactMajor[0]) >= 17;
11
+ }
12
+
13
+ /**
14
+ * Recurse through `error.cause` chain to set cause on an error.
15
+ */
16
+ function setCause(error, cause) {
17
+ const seenErrors = new WeakSet();
18
+
19
+ function recurse(error, cause) {
20
+ // If we've already seen the error, there is a recursive loop somewhere in the error's
21
+ // cause chain. Let's just bail out then to prevent a stack overflow.
22
+ if (seenErrors.has(error)) {
23
+ return;
24
+ }
25
+ if (error.cause) {
26
+ seenErrors.add(error);
27
+ return recurse(error.cause, cause);
28
+ }
29
+ error.cause = cause;
30
+ }
31
+
32
+ recurse(error, cause);
33
+ }
34
+
35
+ /**
36
+ * Captures an error that was thrown by a React ErrorBoundary or React root.
37
+ *
38
+ * @param error The error to capture.
39
+ * @param errorInfo The errorInfo provided by React.
40
+ * @param hint Optional additional data to attach to the Sentry event.
41
+ * @returns the id of the captured Sentry event.
42
+ */
43
+ function captureReactException(
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ error,
46
+ { componentStack },
47
+ hint,
48
+ ) {
49
+ // If on React version >= 17, create stack trace from componentStack param and links
50
+ // to to the original error using `error.cause` otherwise relies on error param for stacktrace.
51
+ // Linking errors requires the `LinkedErrors` integration be enabled.
52
+ // See: https://reactjs.org/blog/2020/08/10/react-v17-rc.html#native-component-stacks
53
+ //
54
+ // Although `componentDidCatch` is typed to accept an `Error` object, it can also be invoked
55
+ // with non-error objects. This is why we need to check if the error is an error-like object.
56
+ // See: https://github.com/getsentry/sentry-javascript/issues/6167
57
+ if (isAtLeastReact17(version) && isError(error) && componentStack) {
58
+ const errorBoundaryError = new Error(error.message);
59
+ errorBoundaryError.name = `React ErrorBoundary ${error.name}`;
60
+ errorBoundaryError.stack = componentStack;
61
+
62
+ // Using the `LinkedErrors` integration to link the errors together.
63
+ setCause(error, errorBoundaryError);
64
+ }
65
+
66
+ return withScope(scope => {
67
+ scope.setContext('react', { componentStack });
68
+ return captureException(error, hint);
69
+ });
70
+ }
71
+
72
+ /**
73
+ * Creates an error handler that can be used with the `onCaughtError`, `onUncaughtError`,
74
+ * and `onRecoverableError` options in `createRoot` and `hydrateRoot` React DOM methods.
75
+ *
76
+ * @param callback An optional callback that will be called after the error is captured.
77
+ * Use this to add custom handling for errors.
78
+ *
79
+ * @example
80
+ *
81
+ * ```JavaScript
82
+ * const root = createRoot(container, {
83
+ * onCaughtError: Sentry.reactErrorHandler(),
84
+ * onUncaughtError: Sentry.reactErrorHandler((error, errorInfo) => {
85
+ * console.warn('Caught error', error, errorInfo.componentStack);
86
+ * });
87
+ * });
88
+ * ```
89
+ */
90
+ function reactErrorHandler(
91
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
92
+ callback,
93
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
+ ) {
95
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
+ return (error, errorInfo) => {
97
+ const hasCallback = !!callback;
98
+ const eventId = captureReactException(error, errorInfo, {
99
+ mechanism: { handled: hasCallback, type: 'auto.function.react.error_handler' },
100
+ });
101
+ if (hasCallback) {
102
+ callback(error, errorInfo, eventId);
103
+ }
104
+ };
105
+ }
106
+
107
+ export { captureReactException, isAtLeastReact17, reactErrorHandler, setCause };
108
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sources":["../../src/error.ts"],"sourcesContent":["import { captureException, withScope } from '@sentry/browser';\nimport { isError } from '@sentry/core';\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":[],"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;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 -0,0 +1,166 @@
1
+ import { getClient, showReportDialog, withScope } from '@sentry/browser';
2
+ import { debug } from '@sentry/core';
3
+ import * as React from 'react';
4
+ import { DEBUG_BUILD } from './debug-build.js';
5
+ import { captureReactException } from './error.js';
6
+ import { hoistNonReactStatics } from './hoist-non-react-statics.js';
7
+
8
+ const UNKNOWN_COMPONENT = 'unknown';
9
+
10
+ const INITIAL_STATE = {
11
+ componentStack: null,
12
+ error: null,
13
+ eventId: null,
14
+ };
15
+
16
+ /**
17
+ * A ErrorBoundary component that logs errors to Sentry.
18
+ * NOTE: If you are a Sentry user, and you are seeing this stack frame, it means the
19
+ * Sentry React SDK ErrorBoundary caught an error invoking your application code. This
20
+ * is expected behavior and NOT indicative of a bug with the Sentry React SDK.
21
+ */
22
+ class ErrorBoundary extends React.Component {
23
+
24
+ constructor(props) {
25
+ super(props);
26
+
27
+ this.state = INITIAL_STATE;
28
+ this._openFallbackReportDialog = true;
29
+
30
+ const client = getClient();
31
+ if (client && props.showDialog) {
32
+ this._openFallbackReportDialog = false;
33
+ this._cleanupHook = client.on('afterSendEvent', event => {
34
+ if (!event.type && this._lastEventId && event.event_id === this._lastEventId) {
35
+ showReportDialog({ ...props.dialogOptions, eventId: this._lastEventId });
36
+ }
37
+ });
38
+ }
39
+ }
40
+
41
+ componentDidCatch(error, errorInfo) {
42
+ const { componentStack } = errorInfo;
43
+ const { beforeCapture, onError, showDialog, dialogOptions } = this.props;
44
+ withScope(scope => {
45
+ if (beforeCapture) {
46
+ beforeCapture(scope, error, componentStack);
47
+ }
48
+
49
+ const handled = this.props.handled != null ? this.props.handled : !!this.props.fallback;
50
+ const eventId = captureReactException(error, errorInfo, {
51
+ mechanism: { handled, type: 'auto.function.react.error_boundary' },
52
+ });
53
+
54
+ if (onError) {
55
+ onError(error, componentStack, eventId);
56
+ }
57
+ if (showDialog) {
58
+ this._lastEventId = eventId;
59
+ if (this._openFallbackReportDialog) {
60
+ showReportDialog({ ...dialogOptions, eventId });
61
+ }
62
+ }
63
+
64
+ // componentDidCatch is used over getDerivedStateFromError
65
+ // so that componentStack is accessible through state.
66
+ this.setState({ error, componentStack, eventId });
67
+ });
68
+ }
69
+
70
+ componentDidMount() {
71
+ const { onMount } = this.props;
72
+ if (onMount) {
73
+ onMount();
74
+ }
75
+ }
76
+
77
+ componentWillUnmount() {
78
+ const { error, componentStack, eventId } = this.state;
79
+ const { onUnmount } = this.props;
80
+ if (onUnmount) {
81
+ if (this.state === INITIAL_STATE) {
82
+ // If the error boundary never encountered an error, call onUnmount with null values
83
+ onUnmount(null, null, null);
84
+ } else {
85
+ // `componentStack` and `eventId` are guaranteed to be non-null here because `onUnmount` is only called
86
+ // when the error boundary has already encountered an error.
87
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
88
+ onUnmount(error, componentStack, eventId);
89
+ }
90
+ }
91
+
92
+ if (this._cleanupHook) {
93
+ this._cleanupHook();
94
+ this._cleanupHook = undefined;
95
+ }
96
+ }
97
+
98
+ resetErrorBoundary() {
99
+ const { onReset } = this.props;
100
+ const { error, componentStack, eventId } = this.state;
101
+ if (onReset) {
102
+ // `componentStack` and `eventId` are guaranteed to be non-null here because `onReset` is only called
103
+ // when the error boundary has already encountered an error.
104
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
105
+ onReset(error, componentStack, eventId);
106
+ }
107
+ this.setState(INITIAL_STATE);
108
+ }
109
+
110
+ render() {
111
+ const { fallback, children } = this.props;
112
+ const state = this.state;
113
+
114
+ // `componentStack` is only null in the initial state, when no error has been captured.
115
+ // If an error has been captured, `componentStack` will be a string.
116
+ // We cannot check `state.error` because null can be thrown as an error.
117
+ if (state.componentStack === null) {
118
+ return typeof children === 'function' ? children() : children;
119
+ }
120
+
121
+ const element =
122
+ typeof fallback === 'function'
123
+ ? React.createElement(fallback, {
124
+ error: state.error,
125
+ componentStack: state.componentStack,
126
+ resetError: () => this.resetErrorBoundary(),
127
+ eventId: state.eventId,
128
+ })
129
+ : fallback;
130
+
131
+ if (React.isValidElement(element)) {
132
+ return element;
133
+ }
134
+
135
+ if (fallback) {
136
+ DEBUG_BUILD && debug.warn('fallback did not produce a valid ReactElement');
137
+ }
138
+
139
+ // Fail gracefully if no fallback provided or is not valid
140
+ return null;
141
+ }
142
+ }
143
+
144
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
145
+ function withErrorBoundary(
146
+ WrappedComponent,
147
+ errorBoundaryOptions,
148
+ ) {
149
+ const componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;
150
+
151
+ const Wrapped = React.memo((props) => (
152
+ React.createElement(ErrorBoundary, { ...errorBoundaryOptions,}
153
+ , React.createElement(WrappedComponent, { ...props,} )
154
+ )
155
+ )) ;
156
+
157
+ Wrapped.displayName = `errorBoundary(${componentDisplayName})`;
158
+
159
+ // Copy over static methods from Wrapped component to Profiler HOC
160
+ // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over
161
+ hoistNonReactStatics(Wrapped, WrappedComponent);
162
+ return Wrapped;
163
+ }
164
+
165
+ export { ErrorBoundary, UNKNOWN_COMPONENT, withErrorBoundary };
166
+ //# sourceMappingURL=errorboundary.js.map
@@ -0,0 +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":[],"mappings":";;;;;;;AASO,MAAM,iBAAA,GAAoB;;AAsEjC,MAAM,aAAa,GAAuB;AAC1C,EAAE,cAAc,EAAE,IAAI;AACtB,EAAE,KAAK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;AACpB,IAAI;;AAEJ,IAAI,IAAI,QAAQ,EAAE;AAClB,MAAM,eAAe,KAAK,CAAC,IAAI,CAAC,+CAA+C,CAAC;AAChF,IAAI;;AAEJ;AACA,IAAI,OAAO,IAAI;AACf,EAAE;AACF;;AAEA;AACA,SAAS,iBAAiB;AAC1B,EAAE,gBAAgB;AAClB,EAAE,oBAAoB;AACtB,EAAe;AACf,EAAE,MAAM,oBAAA,GAAuB,gBAAgB,CAAC,WAAA,IAAe,gBAAgB,CAAC,IAAA,IAAQ,iBAAiB;;AAEzG,EAAE,MAAM,OAAA,GAAU,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK;AACnC,IAAI,KAAA,CAAA,aAAA,CAAC,aAAA,EAAA,EAAc,GAAI,oBAAoB;AAC3C,QAAM,KAAA,CAAA,aAAA,CAAC,gBAAA,EAAA,EAAiB,GAAI,KAAK;AACjC;AACA,GAAG,CAAA;;AAEH,EAAE,OAAO,CAAC,WAAA,GAAc,CAAC,cAAc,EAAE,oBAAoB,CAAC,CAAC,CAAC;;AAEhE;AACA;AACA,EAAE,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,CAAC;AACjD,EAAE,OAAO,OAAO;AAChB;;;;"}
@@ -0,0 +1,157 @@
1
+ /**
2
+ * React statics that should not be hoisted
3
+ */
4
+ const REACT_STATICS = {
5
+ childContextTypes: true,
6
+ contextType: true,
7
+ contextTypes: true,
8
+ defaultProps: true,
9
+ displayName: true,
10
+ getDefaultProps: true,
11
+ getDerivedStateFromError: true,
12
+ getDerivedStateFromProps: true,
13
+ mixins: true,
14
+ propTypes: true,
15
+ type: true,
16
+ } ;
17
+
18
+ /**
19
+ * Known JavaScript function statics that should not be hoisted
20
+ */
21
+ const KNOWN_STATICS = {
22
+ name: true,
23
+ length: true,
24
+ prototype: true,
25
+ caller: true,
26
+ callee: true,
27
+ arguments: true,
28
+ arity: true,
29
+ } ;
30
+
31
+ /**
32
+ * Statics specific to ForwardRef components
33
+ */
34
+ const FORWARD_REF_STATICS = {
35
+ $$typeof: true,
36
+ render: true,
37
+ defaultProps: true,
38
+ displayName: true,
39
+ propTypes: true,
40
+ } ;
41
+
42
+ /**
43
+ * Statics specific to Memo components
44
+ */
45
+ const MEMO_STATICS = {
46
+ $$typeof: true,
47
+ compare: true,
48
+ defaultProps: true,
49
+ displayName: true,
50
+ propTypes: true,
51
+ type: true,
52
+ } ;
53
+
54
+ /**
55
+ * Inlined react-is utilities
56
+ * We only need to detect ForwardRef and Memo types
57
+ */
58
+ const ForwardRefType = Symbol.for('react.forward_ref');
59
+ const MemoType = Symbol.for('react.memo');
60
+
61
+ /**
62
+ * Check if a component is a Memo component
63
+ */
64
+ function isMemo(component) {
65
+ return (
66
+ typeof component === 'object' && component !== null && (component ).$$typeof === MemoType
67
+ );
68
+ }
69
+
70
+ /**
71
+ * Map of React component types to their specific statics
72
+ */
73
+ const TYPE_STATICS = {};
74
+ TYPE_STATICS[ForwardRefType] = FORWARD_REF_STATICS;
75
+ TYPE_STATICS[MemoType] = MEMO_STATICS;
76
+
77
+ /**
78
+ * Get the appropriate statics object for a given component
79
+ */
80
+ function getStatics(component) {
81
+ // React v16.11 and below
82
+ if (isMemo(component)) {
83
+ return MEMO_STATICS;
84
+ }
85
+
86
+ // React v16.12 and above
87
+ const componentType = (component ).$$typeof;
88
+ return (componentType && TYPE_STATICS[componentType]) || REACT_STATICS;
89
+ }
90
+
91
+ const defineProperty = Object.defineProperty.bind(Object);
92
+ const getOwnPropertyNames = Object.getOwnPropertyNames.bind(Object);
93
+ const getOwnPropertySymbols = Object.getOwnPropertySymbols?.bind(Object);
94
+ const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor.bind(Object);
95
+ const getPrototypeOf = Object.getPrototypeOf.bind(Object);
96
+ const objectPrototype = Object.prototype;
97
+
98
+ /**
99
+ * Copies non-react specific statics from a child component to a parent component.
100
+ * Similar to Object.assign, but copies all static properties from source to target,
101
+ * excluding React-specific statics and known JavaScript statics.
102
+ *
103
+ * @param targetComponent - The component to copy statics to
104
+ * @param sourceComponent - The component to copy statics from
105
+ * @param excludelist - An optional object of keys to exclude from hoisting
106
+ * @returns The target component with hoisted statics
107
+ */
108
+ function hoistNonReactStatics
109
+
110
+ (targetComponent, sourceComponent, excludelist) {
111
+ if (typeof sourceComponent !== 'string') {
112
+ // Don't hoist over string (html) components
113
+ if (objectPrototype) {
114
+ const inheritedComponent = getPrototypeOf(sourceComponent);
115
+
116
+ if (inheritedComponent && inheritedComponent !== objectPrototype) {
117
+ hoistNonReactStatics(targetComponent, inheritedComponent);
118
+ }
119
+ }
120
+
121
+ let keys = getOwnPropertyNames(sourceComponent);
122
+
123
+ if (getOwnPropertySymbols) {
124
+ keys = keys.concat(getOwnPropertySymbols(sourceComponent));
125
+ }
126
+
127
+ const targetStatics = getStatics(targetComponent);
128
+ const sourceStatics = getStatics(sourceComponent);
129
+
130
+ for (const key of keys) {
131
+ // Use key directly - String(key) throws for Symbols if minified to '' + key (#18966)
132
+ if (
133
+ !KNOWN_STATICS[key ] &&
134
+ true &&
135
+ !sourceStatics?.[key ] &&
136
+ !targetStatics?.[key ] &&
137
+ !getOwnPropertyDescriptor(targetComponent, key) // Don't overwrite existing properties
138
+ ) {
139
+ const descriptor = getOwnPropertyDescriptor(sourceComponent, key);
140
+
141
+ if (descriptor) {
142
+ try {
143
+ // Avoid failures from read-only properties
144
+ defineProperty(targetComponent, key, descriptor);
145
+ } catch (_e) {
146
+ // Silently ignore errors
147
+ }
148
+ }
149
+ }
150
+ }
151
+ }
152
+
153
+ return targetComponent;
154
+ }
155
+
156
+ export { hoistNonReactStatics };
157
+ //# sourceMappingURL=hoist-non-react-statics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hoist-non-react-statics.js","sources":["../../src/hoist-non-react-statics.ts"],"sourcesContent":["/**\n * Inlined implementation of hoist-non-react-statics\n * Original library: https://github.com/mridgway/hoist-non-react-statics\n * License: BSD-3-Clause\n * Copyright 2015, Yahoo! Inc.\n *\n * This is an inlined version to avoid ESM compatibility issues with the original package.\n */\n\nimport type * as React from 'react';\n\n/**\n * React statics that should not be hoisted\n */\nconst REACT_STATICS = {\n childContextTypes: true,\n contextType: true,\n contextTypes: true,\n defaultProps: true,\n displayName: true,\n getDefaultProps: true,\n getDerivedStateFromError: true,\n getDerivedStateFromProps: true,\n mixins: true,\n propTypes: true,\n type: true,\n} as const;\n\n/**\n * Known JavaScript function statics that should not be hoisted\n */\nconst KNOWN_STATICS = {\n name: true,\n length: true,\n prototype: true,\n caller: true,\n callee: true,\n arguments: true,\n arity: true,\n} as const;\n\n/**\n * Statics specific to ForwardRef components\n */\nconst FORWARD_REF_STATICS = {\n $$typeof: true,\n render: true,\n defaultProps: true,\n displayName: true,\n propTypes: true,\n} as const;\n\n/**\n * Statics specific to Memo components\n */\nconst MEMO_STATICS = {\n $$typeof: true,\n compare: true,\n defaultProps: true,\n displayName: true,\n propTypes: true,\n type: true,\n} as const;\n\n/**\n * Inlined react-is utilities\n * We only need to detect ForwardRef and Memo types\n */\nconst ForwardRefType = Symbol.for('react.forward_ref');\nconst MemoType = Symbol.for('react.memo');\n\n/**\n * Check if a component is a Memo component\n */\nfunction isMemo(component: unknown): boolean {\n return (\n typeof component === 'object' && component !== null && (component as { $$typeof?: symbol }).$$typeof === MemoType\n );\n}\n\n/**\n * Map of React component types to their specific statics\n */\nconst TYPE_STATICS: Record<symbol, Record<string, boolean>> = {};\nTYPE_STATICS[ForwardRefType] = FORWARD_REF_STATICS;\nTYPE_STATICS[MemoType] = MEMO_STATICS;\n\n/**\n * Get the appropriate statics object for a given component\n */\nfunction getStatics(component: React.ComponentType<unknown>): Record<string, boolean> {\n // React v16.11 and below\n if (isMemo(component)) {\n return MEMO_STATICS;\n }\n\n // React v16.12 and above\n const componentType = (component as { $$typeof?: symbol }).$$typeof;\n return (componentType && TYPE_STATICS[componentType]) || REACT_STATICS;\n}\n\nconst defineProperty = Object.defineProperty.bind(Object);\nconst getOwnPropertyNames = Object.getOwnPropertyNames.bind(Object);\nconst getOwnPropertySymbols = Object.getOwnPropertySymbols?.bind(Object);\nconst getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor.bind(Object);\nconst getPrototypeOf = Object.getPrototypeOf.bind(Object);\nconst objectPrototype = Object.prototype;\n\n/**\n * Copies non-react specific statics from a child component to a parent component.\n * Similar to Object.assign, but copies all static properties from source to target,\n * excluding React-specific statics and known JavaScript statics.\n *\n * @param targetComponent - The component to copy statics to\n * @param sourceComponent - The component to copy statics from\n * @param excludelist - An optional object of keys to exclude from hoisting\n * @returns The target component with hoisted statics\n */\nexport function hoistNonReactStatics<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends React.ComponentType<any>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n S extends React.ComponentType<any>,\n C extends Record<string, boolean> = Record<string, never>,\n>(targetComponent: T, sourceComponent: S, excludelist?: C): T {\n if (typeof sourceComponent !== 'string') {\n // Don't hoist over string (html) components\n if (objectPrototype) {\n const inheritedComponent = getPrototypeOf(sourceComponent);\n\n if (inheritedComponent && inheritedComponent !== objectPrototype) {\n hoistNonReactStatics(targetComponent, inheritedComponent, excludelist);\n }\n }\n\n let keys: (string | symbol)[] = getOwnPropertyNames(sourceComponent);\n\n if (getOwnPropertySymbols) {\n keys = keys.concat(getOwnPropertySymbols(sourceComponent));\n }\n\n const targetStatics = getStatics(targetComponent);\n const sourceStatics = getStatics(sourceComponent);\n\n for (const key of keys) {\n // Use key directly - String(key) throws for Symbols if minified to '' + key (#18966)\n if (\n !KNOWN_STATICS[key as keyof typeof KNOWN_STATICS] &&\n !excludelist?.[key as keyof C] &&\n !sourceStatics?.[key as string] &&\n !targetStatics?.[key as string] &&\n !getOwnPropertyDescriptor(targetComponent, key) // Don't overwrite existing properties\n ) {\n const descriptor = getOwnPropertyDescriptor(sourceComponent, key);\n\n if (descriptor) {\n try {\n // Avoid failures from read-only properties\n defineProperty(targetComponent, key, descriptor);\n } catch (_e) {\n // Silently ignore errors\n }\n }\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AM,MAAM,kBAAA,GAAqB,cAAc,CAAC,eAAe,CAAC;;AAEhE,MAAM,IAAI,kBAAA,IAAsB,kBAAA,KAAuB,eAAe,EAAE;AACxE,QAAQ,oBAAoB,CAAC,eAAe,EAAE,kBAA+B,CAAC;AAC9E,MAAM;AACN,IAAI;;AAEJ,IAAI,IAAI,IAAI,GAAwB,mBAAmB,CAAC,eAAe,CAAC;;AAExE,IAAI,IAAI,qBAAqB,EAAE;AAC/B,MAAM,IAAA,GAAO,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,eAAe,CAAC,CAAC;AAChE,IAAI;;AAEJ,IAAI,MAAM,aAAA,GAAgB,UAAU,CAAC,eAAe,CAAC;AACrD,IAAI,MAAM,aAAA,GAAgB,UAAU,CAAC,eAAe,CAAC;;AAErD,IAAI,KAAK,MAAM,GAAA,IAAO,IAAI,EAAE;AAC5B;AACA,MAAM;AACN,QAAQ,CAAC,aAAa,CAAC,GAAA,EAAI;AAC3B,QAAQ,IAAmB;AAC3B,QAAQ,CAAC,aAAa,GAAG,KAAI;AAC7B,QAAQ,CAAC,aAAa,GAAG,KAAI;AAC7B,QAAQ,CAAC,wBAAwB,CAAC,eAAe,EAAE,GAAG,CAAA;AACtD,QAAQ;AACR,QAAQ,MAAM,aAAa,wBAAwB,CAAC,eAAe,EAAE,GAAG,CAAC;;AAEzE,QAAQ,IAAI,UAAU,EAAE;AACxB,UAAU,IAAI;AACd;AACA,YAAY,cAAc,CAAC,eAAe,EAAE,GAAG,EAAE,UAAU,CAAC;AAC5D,UAAU,CAAA,CAAE,OAAO,EAAE,EAAE;AACvB;AACA,UAAU;AACV,QAAQ;AACR,MAAM;AACN,IAAI;AACJ,EAAE;;AAEF,EAAE,OAAO,eAAe;AACxB;;;;"}
@@ -0,0 +1,12 @@
1
+ export * from '@sentry/browser';
2
+ export { init } from './sdk.js';
3
+ export { captureReactException, reactErrorHandler } from './error.js';
4
+ export { Profiler, useProfiler, withProfiler } from './profiler.js';
5
+ export { ErrorBoundary, withErrorBoundary } from './errorboundary.js';
6
+ export { createReduxEnhancer } from './redux.js';
7
+ export { reactRouterV3BrowserTracingIntegration } from './reactrouterv3.js';
8
+ export { tanstackRouterBrowserTracingIntegration } from './tanstackrouter.js';
9
+ export { reactRouterV4BrowserTracingIntegration, reactRouterV5BrowserTracingIntegration, withSentryRouting } from './reactrouter.js';
10
+ export { reactRouterV6BrowserTracingIntegration, withSentryReactRouterV6Routing, wrapCreateBrowserRouterV6, wrapCreateMemoryRouterV6, wrapUseRoutesV6 } from './reactrouterv6.js';
11
+ export { reactRouterV7BrowserTracingIntegration, withSentryReactRouterV7Routing, wrapCreateBrowserRouterV7, wrapCreateMemoryRouterV7, wrapUseRoutesV7 } from './reactrouterv7.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
@@ -0,0 +1 @@
1
+ {"type":"module","version":"10.44.0","sideEffects":false}