@sentry/react 7.0.0-alpha.1 → 7.0.0-beta.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.
- package/cjs/errorboundary.d.ts +1 -0
- package/cjs/errorboundary.d.ts.map +1 -1
- package/cjs/errorboundary.js +43 -48
- package/cjs/errorboundary.js.map +1 -1
- package/cjs/index.js +1 -1
- package/cjs/profiler.js +53 -60
- package/cjs/profiler.js.map +1 -1
- package/cjs/reactrouter.js +22 -26
- package/cjs/reactrouter.js.map +1 -1
- package/cjs/reactrouterv3.js +21 -29
- package/cjs/reactrouterv3.js.map +1 -1
- package/cjs/redux.js +38 -41
- package/cjs/redux.js.map +1 -1
- package/cjs/sdk.js +1 -1
- package/cjs/sdk.js.map +1 -1
- package/esm/constants.js +3 -3
- package/esm/constants.js.map +1 -1
- package/esm/errorboundary.d.ts +1 -0
- package/esm/errorboundary.d.ts.map +1 -1
- package/esm/errorboundary.js +38 -44
- package/esm/errorboundary.js.map +1 -1
- package/esm/flags.js +1 -1
- package/esm/flags.js.map +1 -1
- package/esm/profiler.js +48 -56
- package/esm/profiler.js.map +1 -1
- package/esm/reactrouter.js +18 -23
- package/esm/reactrouter.js.map +1 -1
- package/esm/reactrouterv3.js +20 -28
- package/esm/reactrouterv3.js.map +1 -1
- package/esm/redux.js +38 -41
- package/esm/redux.js.map +1 -1
- package/package.json +4 -5
- package/types/errorboundary.d.ts +1 -0
- package/types/errorboundary.d.ts.map +1 -1
package/cjs/reactrouter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactrouter.js","sourceRoot":"","sources":["../../src/reactrouter.tsx"],"names":[],"mappings":";;AACA,
|
|
1
|
+
{"version":3,"file":"reactrouter.js","sourceRoot":"","sources":["../../src/reactrouter.tsx"],"names":[],"mappings":";;AACA,yCAAgD;AAChD,8FAA2D;AAC3D,qDAA+B;AAuB/B,sDAAsD;AAEtD,MAAM,MAAM,GAAG,uBA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AClE,2IAA2I;IAC3I,OAAO,YAAY,CAAC;AACtB,CAAC;AApBD,8CAoBC;AACD,kGAAkG","sourcesContent":["import { Transaction } from '@sentry/types';\nimport { getGlobalObject } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { Action, Location, ReactRouterInstrumentation } from './types';\n\n// We need to disable eslint no-explict-any because any is required for the\n// react-router typings.\n/* eslint-disable @typescript-eslint/no-explicit-any */\ntype Match = { path: string; url: string; params: Record<string, any>; isExact: boolean };\n\nexport type RouterHistory = {\n location?: Location;\n listen?(cb: (location: Location, action: Action) => void): void;\n} & Record<string, any>;\n\nexport type RouteConfig = {\n [propName: string]: any;\n path?: string | string[];\n exact?: boolean;\n component?: JSX.Element;\n routes?: RouteConfig[];\n};\n\ntype MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null;\n/* eslint-enable @typescript-eslint/no-explicit-any */\n\nconst global = getGlobalObject<Window>();\n\nlet activeTransaction: Transaction | undefined;\n\nexport function reactRouterV4Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);\n}\n\nexport function reactRouterV5Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);\n}\n\nfunction createReactRouterInstrumentation(\n history: RouterHistory,\n name: string,\n allRoutes: RouteConfig[] = [],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n function getInitPathName(): string | undefined {\n if (history && history.location) {\n return history.location.pathname;\n }\n\n if (global && global.location) {\n return global.location.pathname;\n }\n\n return undefined;\n }\n\n function getTransactionName(pathname: string): string {\n if (allRoutes.length === 0 || !matchPath) {\n return pathname;\n }\n\n const branches = matchRoutes(allRoutes, pathname, matchPath);\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let x = 0; x < branches.length; x++) {\n if (branches[x].match.isExact) {\n return branches[x].match.path;\n }\n }\n\n return pathname;\n }\n\n return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true): void => {\n const initPathName = getInitPathName();\n if (startTransactionOnPageLoad && initPathName) {\n activeTransaction = customStartTransaction({\n name: getTransactionName(initPathName),\n op: 'pageload',\n tags: {\n 'routing.instrumentation': name,\n },\n });\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen((location, action) => {\n if (action && (action === 'PUSH' || action === 'POP')) {\n if (activeTransaction) {\n activeTransaction.finish();\n }\n const tags = {\n 'routing.instrumentation': name,\n };\n\n activeTransaction = customStartTransaction({\n name: getTransactionName(location.pathname),\n op: 'navigation',\n tags,\n });\n }\n });\n }\n };\n}\n\n/**\n * Matches a set of routes to a pathname\n * Based on implementation from\n */\nfunction matchRoutes(\n routes: RouteConfig[],\n pathname: string,\n matchPath: MatchPath,\n branch: Array<{ route: RouteConfig; match: Match }> = [],\n): Array<{ route: RouteConfig; match: Match }> {\n routes.some(route => {\n const match = route.path\n ? matchPath(pathname, route)\n : branch.length\n ? branch[branch.length - 1].match // use parent match\n : computeRootMatch(pathname); // use default \"root\" match\n\n if (match) {\n branch.push({ route, match });\n\n if (route.routes) {\n matchRoutes(route.routes, pathname, matchPath, branch);\n }\n }\n\n return !!match;\n });\n\n return branch;\n}\n\nfunction computeRootMatch(pathname: string): Match {\n return { path: '/', url: '/', params: {}, isExact: pathname === '/' };\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\nexport function withSentryRouting<P extends Record<string, any>, R extends React.ComponentType<P>>(Route: R): R {\n const componentDisplayName = (Route as any).displayName || (Route as any).name;\n\n const WrappedRoute: React.FC<P> = (props: P) => {\n if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {\n activeTransaction.setName(props.computedMatch.path);\n }\n\n // @ts-ignore Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return <Route {...props} />;\n };\n\n WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;\n hoistNonReactStatics(WrappedRoute, Route);\n // @ts-ignore Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return WrappedRoute;\n}\n/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\n"]}
|
package/cjs/reactrouterv3.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const utils_1 = require("@sentry/utils");
|
|
3
|
+
const global = utils_1.getGlobalObject();
|
|
4
4
|
/**
|
|
5
5
|
* Creates routing instrumentation for React Router v3
|
|
6
6
|
* Works for React Router >= 3.2.0 and < 4.0.0
|
|
@@ -10,14 +10,12 @@ var global = utils_1.getGlobalObject();
|
|
|
10
10
|
* @param match `Router.match` utility
|
|
11
11
|
*/
|
|
12
12
|
function reactRouterV3Instrumentation(history, routes, match) {
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var activeTransaction;
|
|
17
|
-
var prevName;
|
|
13
|
+
return (startTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true) => {
|
|
14
|
+
let activeTransaction;
|
|
15
|
+
let prevName;
|
|
18
16
|
// Have to use global.location because history.location might not be defined.
|
|
19
17
|
if (startTransactionOnPageLoad && global && global.location) {
|
|
20
|
-
normalizeTransactionName(routes, global.location, match,
|
|
18
|
+
normalizeTransactionName(routes, global.location, match, (localName) => {
|
|
21
19
|
prevName = localName;
|
|
22
20
|
activeTransaction = startTransaction({
|
|
23
21
|
name: prevName,
|
|
@@ -29,23 +27,23 @@ function reactRouterV3Instrumentation(history, routes, match) {
|
|
|
29
27
|
});
|
|
30
28
|
}
|
|
31
29
|
if (startTransactionOnLocationChange && history.listen) {
|
|
32
|
-
history.listen(
|
|
30
|
+
history.listen(location => {
|
|
33
31
|
if (location.action === 'PUSH' || location.action === 'POP') {
|
|
34
32
|
if (activeTransaction) {
|
|
35
33
|
activeTransaction.finish();
|
|
36
34
|
}
|
|
37
|
-
|
|
35
|
+
const tags = {
|
|
38
36
|
'routing.instrumentation': 'react-router-v3',
|
|
39
37
|
};
|
|
40
38
|
if (prevName) {
|
|
41
|
-
|
|
39
|
+
tags.from = prevName;
|
|
42
40
|
}
|
|
43
|
-
normalizeTransactionName(routes, location, match,
|
|
41
|
+
normalizeTransactionName(routes, location, match, (localName) => {
|
|
44
42
|
prevName = localName;
|
|
45
43
|
activeTransaction = startTransaction({
|
|
46
44
|
name: prevName,
|
|
47
45
|
op: 'navigation',
|
|
48
|
-
tags
|
|
46
|
+
tags,
|
|
49
47
|
});
|
|
50
48
|
});
|
|
51
49
|
}
|
|
@@ -58,15 +56,15 @@ exports.reactRouterV3Instrumentation = reactRouterV3Instrumentation;
|
|
|
58
56
|
* Normalize transaction names using `Router.match`
|
|
59
57
|
*/
|
|
60
58
|
function normalizeTransactionName(appRoutes, location, match, callback) {
|
|
61
|
-
|
|
59
|
+
let name = location.pathname;
|
|
62
60
|
match({
|
|
63
|
-
location
|
|
61
|
+
location,
|
|
64
62
|
routes: appRoutes,
|
|
65
|
-
},
|
|
63
|
+
}, (error, _redirectLocation, renderProps) => {
|
|
66
64
|
if (error || !renderProps) {
|
|
67
65
|
return callback(name);
|
|
68
66
|
}
|
|
69
|
-
|
|
67
|
+
const routePath = getRouteStringFromRoutes(renderProps.routes || []);
|
|
70
68
|
if (routePath.length === 0 || routePath === '/*') {
|
|
71
69
|
return callback(name);
|
|
72
70
|
}
|
|
@@ -81,10 +79,10 @@ function getRouteStringFromRoutes(routes) {
|
|
|
81
79
|
if (!Array.isArray(routes) || routes.length === 0) {
|
|
82
80
|
return '';
|
|
83
81
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
for (
|
|
87
|
-
|
|
82
|
+
const routesWithPaths = routes.filter((route) => !!route.path);
|
|
83
|
+
let index = -1;
|
|
84
|
+
for (let x = routesWithPaths.length - 1; x >= 0; x--) {
|
|
85
|
+
const route = routesWithPaths[x];
|
|
88
86
|
if (route.path && route.path.startsWith('/')) {
|
|
89
87
|
index = x;
|
|
90
88
|
break;
|
|
@@ -92,14 +90,8 @@ function getRouteStringFromRoutes(routes) {
|
|
|
92
90
|
}
|
|
93
91
|
return routesWithPaths
|
|
94
92
|
.slice(index)
|
|
95
|
-
.filter(
|
|
96
|
-
|
|
97
|
-
return !!path;
|
|
98
|
-
})
|
|
99
|
-
.map(function (_a) {
|
|
100
|
-
var path = _a.path;
|
|
101
|
-
return path;
|
|
102
|
-
})
|
|
93
|
+
.filter(({ path }) => !!path)
|
|
94
|
+
.map(({ path }) => path)
|
|
103
95
|
.join('');
|
|
104
96
|
}
|
|
105
97
|
//# sourceMappingURL=reactrouterv3.js.map
|
package/cjs/reactrouterv3.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactrouterv3.js","sourceRoot":"","sources":["../../src/reactrouterv3.ts"],"names":[],"mappings":";AACA,
|
|
1
|
+
{"version":3,"file":"reactrouterv3.js","sourceRoot":"","sources":["../../src/reactrouterv3.ts"],"names":[],"mappings":";AACA,yCAAgD;AAoBhD,MAAM,MAAM,GAAG,uBAAe,EAAU,CAAC;AAEzC;;;;;;;GAOG;AACH,SAAgB,4BAA4B,CAC1C,OAAkB,EAClB,MAAe,EACf,KAAY;IAEZ,OAAO,CACL,gBAA0E,EAC1E,6BAAsC,IAAI,EAC1C,mCAA4C,IAAI,EAChD,EAAE;QACF,IAAI,iBAA0C,CAAC;QAC/C,IAAI,QAA4B,CAAC;QAEjC,6EAA6E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;SACZ,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;SAC5B,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC;SACvB,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC","sourcesContent":["import { Primitive, Transaction, TransactionContext } from '@sentry/types';\nimport { getGlobalObject } from '@sentry/utils';\n\nimport { Location, ReactRouterInstrumentation } from './types';\n\n// Many of the types below had to be mocked out to prevent typescript issues\n// these types are required for correct functionality.\n\ntype HistoryV3 = {\n location?: Location;\n listen?(cb: (location: Location) => void): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n} & Record<string, any>;\n\nexport type Route = { path?: string; childRoutes?: Route[] };\n\nexport type Match = (\n props: { location: Location; routes: Route[] },\n cb: (error?: Error, _redirectLocation?: Location, renderProps?: { routes?: Route[] }) => void,\n) => void;\n\nconst global = getGlobalObject<Window>();\n\n/**\n * Creates routing instrumentation for React Router v3\n * Works for React Router >= 3.2.0 and < 4.0.0\n *\n * @param history object from the `history` library\n * @param routes a list of all routes, should be\n * @param match `Router.match` utility\n */\nexport function reactRouterV3Instrumentation(\n history: HistoryV3,\n routes: Route[],\n match: Match,\n): ReactRouterInstrumentation {\n return (\n startTransaction: (context: TransactionContext) => Transaction | undefined,\n startTransactionOnPageLoad: boolean = true,\n startTransactionOnLocationChange: boolean = true,\n ) => {\n let activeTransaction: Transaction | undefined;\n let prevName: string | undefined;\n\n // Have to use global.location because history.location might not be defined.\n if (startTransactionOnPageLoad && global && global.location) {\n normalizeTransactionName(routes, global.location as unknown as Location, match, (localName: string) => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'pageload',\n tags: {\n 'routing.instrumentation': 'react-router-v3',\n },\n });\n });\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen(location => {\n if (location.action === 'PUSH' || location.action === 'POP') {\n if (activeTransaction) {\n activeTransaction.finish();\n }\n const tags: Record<string, Primitive> = {\n 'routing.instrumentation': 'react-router-v3',\n };\n if (prevName) {\n tags.from = prevName;\n }\n normalizeTransactionName(routes, location, match, (localName: string) => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'navigation',\n tags,\n });\n });\n }\n });\n }\n };\n}\n\n/**\n * Normalize transaction names using `Router.match`\n */\nfunction normalizeTransactionName(\n appRoutes: Route[],\n location: Location,\n match: Match,\n callback: (pathname: string) => void,\n): void {\n let name = location.pathname;\n match(\n {\n location,\n routes: appRoutes,\n },\n (error, _redirectLocation, renderProps) => {\n if (error || !renderProps) {\n return callback(name);\n }\n\n const routePath = getRouteStringFromRoutes(renderProps.routes || []);\n if (routePath.length === 0 || routePath === '/*') {\n return callback(name);\n }\n\n name = routePath;\n return callback(name);\n },\n );\n}\n\n/**\n * Generate route name from array of routes\n */\nfunction getRouteStringFromRoutes(routes: Route[]): string {\n if (!Array.isArray(routes) || routes.length === 0) {\n return '';\n }\n\n const routesWithPaths: Route[] = routes.filter((route: Route) => !!route.path);\n\n let index = -1;\n for (let x = routesWithPaths.length - 1; x >= 0; x--) {\n const route = routesWithPaths[x];\n if (route.path && route.path.startsWith('/')) {\n index = x;\n break;\n }\n }\n\n return routesWithPaths\n .slice(index)\n .filter(({ path }) => !!path)\n .map(({ path }) => path)\n .join('');\n}\n"]}
|
package/cjs/redux.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
var tslib_1 = require("tslib");
|
|
3
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
actionTransformer:
|
|
10
|
-
stateTransformer:
|
|
3
|
+
const browser_1 = require("@sentry/browser");
|
|
4
|
+
const ACTION_BREADCRUMB_CATEGORY = 'redux.action';
|
|
5
|
+
const ACTION_BREADCRUMB_TYPE = 'info';
|
|
6
|
+
const STATE_CONTEXT_KEY = 'redux.state';
|
|
7
|
+
const defaultOptions = {
|
|
8
|
+
actionTransformer: action => action,
|
|
9
|
+
stateTransformer: state => state || null,
|
|
11
10
|
};
|
|
12
11
|
/**
|
|
13
12
|
* Creates an enhancer that would be passed to Redux's createStore to log actions and the latest state to Sentry.
|
|
@@ -16,40 +15,38 @@ var defaultOptions = {
|
|
|
16
15
|
*/
|
|
17
16
|
function createReduxEnhancer(enhancerOptions) {
|
|
18
17
|
// Note: We return an any type as to not have type conflicts.
|
|
19
|
-
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return newState;
|
|
50
|
-
};
|
|
51
|
-
return next(sentryReducer, initialState);
|
|
18
|
+
const options = Object.assign(Object.assign({}, defaultOptions), enhancerOptions);
|
|
19
|
+
return (next) => (reducer, initialState) => {
|
|
20
|
+
const sentryReducer = (state, action) => {
|
|
21
|
+
const newState = reducer(state, action);
|
|
22
|
+
browser_1.configureScope(scope => {
|
|
23
|
+
/* Action breadcrumbs */
|
|
24
|
+
const transformedAction = options.actionTransformer(action);
|
|
25
|
+
if (typeof transformedAction !== 'undefined' && transformedAction !== null) {
|
|
26
|
+
scope.addBreadcrumb({
|
|
27
|
+
category: ACTION_BREADCRUMB_CATEGORY,
|
|
28
|
+
data: transformedAction,
|
|
29
|
+
type: ACTION_BREADCRUMB_TYPE,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/* Set latest state to scope */
|
|
33
|
+
const transformedState = options.stateTransformer(newState);
|
|
34
|
+
if (typeof transformedState !== 'undefined' && transformedState !== null) {
|
|
35
|
+
scope.setContext(STATE_CONTEXT_KEY, transformedState);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
scope.setContext(STATE_CONTEXT_KEY, null);
|
|
39
|
+
}
|
|
40
|
+
/* Allow user to configure scope with latest state */
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
42
|
+
const { configureScopeWithState } = options;
|
|
43
|
+
if (typeof configureScopeWithState === 'function') {
|
|
44
|
+
configureScopeWithState(scope, newState);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return newState;
|
|
52
48
|
};
|
|
49
|
+
return next(sentryReducer, initialState);
|
|
53
50
|
};
|
|
54
51
|
}
|
|
55
52
|
exports.createReduxEnhancer = createReduxEnhancer;
|
package/cjs/redux.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redux.js","sourceRoot":"","sources":["../../src/redux.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"redux.js","sourceRoot":"","sources":["../../src/redux.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,6CAAiD;AAmEjD,MAAM,0BAA0B,GAAG,cAAc,CAAC;AAClD,MAAM,sBAAsB,GAAG,MAAM,CAAC;AACtC,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAExC,MAAM,cAAc,GAA0B;IAC5C,iBAAiB,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM;IACnC,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,IAAI,IAAI;CACzC,CAAC;AAEF;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,eAAgD;IAC3E,6DAA6D;IAC7D,MAAM,OAAO,mCACR,cAAc,GACd,eAAe,CACnB,CAAC;IAEF,OAAO,CAAC,IAA+B,EAA6B,EAAE,CACpE,CAAwC,OAAsB,EAAE,YAAgC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'@sentry/types';\n\ninterface Action<T = any> {\n type: T;\n}\n\ninterface AnyAction extends Action {\n [extraProps: string]: any;\n}\n\ntype Reducer<S = any, A extends Action = AnyAction> = (state: S | undefined, action: A) => S;\n\ntype Dispatch<A extends Action = AnyAction> = <T extends A>(action: T, ...extraArgs: any[]) => T;\n\ntype ExtendState<State, Extension> = [Extension] extends [never] ? State : State & Extension;\n\ntype Unsubscribe = () => void;\n\ninterface Store<S = any, A extends Action = AnyAction, StateExt = never, Ext = Record<string, unknown>> {\n dispatch: Dispatch<A>;\n getState(): S;\n subscribe(listener: () => void): Unsubscribe;\n replaceReducer<NewState, NewActions extends Action>(\n nextReducer: Reducer<NewState, NewActions>,\n ): Store<ExtendState<NewState, StateExt>, NewActions, StateExt, Ext> & Ext;\n}\n\ndeclare const $CombinedState: unique symbol;\n\ntype CombinedState<S> = { readonly [$CombinedState]?: undefined } & S;\n\ntype PreloadedState<S> = Required<S> extends {\n [$CombinedState]: undefined;\n}\n ? S extends CombinedState<infer S1>\n ? { [K in keyof S1]?: S1[K] extends Record<string, unknown> ? PreloadedState<S1[K]> : S1[K] }\n : never\n : { [K in keyof S]: S[K] extends string | number | boolean | symbol ? S[K] : PreloadedState<S[K]> };\n\ntype StoreEnhancerStoreCreator<Ext = Record<string, unknown>, StateExt = never> = <\n S = any,\n A extends Action = AnyAction,\n>(\n reducer: Reducer<S, A>,\n preloadedState?: PreloadedState<S>,\n) => Store<ExtendState<S, StateExt>, A, StateExt, Ext> & Ext;\n\nexport interface SentryEnhancerOptions<S = any> {\n /**\n * Transforms the state before attaching it to an event.\n * Use this to remove any private data before sending it to Sentry.\n * Return null to not attach the state.\n */\n stateTransformer(state: S | undefined): (S & any) | null;\n /**\n * Transforms the action before sending it as a breadcrumb.\n * Use this to remove any private data before sending it to Sentry.\n * Return null to not send the breadcrumb.\n */\n actionTransformer(action: AnyAction): AnyAction | null;\n /**\n * Called on every state update, configure the Sentry Scope with the redux state.\n */\n configureScopeWithState?(scope: Scope, state: S): void;\n}\n\nconst ACTION_BREADCRUMB_CATEGORY = 'redux.action';\nconst ACTION_BREADCRUMB_TYPE = 'info';\nconst STATE_CONTEXT_KEY = 'redux.state';\n\nconst defaultOptions: SentryEnhancerOptions = {\n actionTransformer: action => action,\n stateTransformer: state => state || null,\n};\n\n/**\n * Creates an enhancer that would be passed to Redux's createStore to log actions and the latest state to Sentry.\n *\n * @param enhancerOptions Options to pass to the enhancer\n */\nfunction createReduxEnhancer(enhancerOptions?: Partial<SentryEnhancerOptions>): any {\n // Note: We return an any type as to not have type conflicts.\n const options = {\n ...defaultOptions,\n ...enhancerOptions,\n };\n\n return (next: StoreEnhancerStoreCreator): StoreEnhancerStoreCreator =>\n <S = any, A extends Action = AnyAction>(reducer: Reducer<S, A>, initialState?: PreloadedState<S>) => {\n const sentryReducer: Reducer<S, A> = (state, action): S => {\n const newState = reducer(state, action);\n\n configureScope(scope => {\n /* Action breadcrumbs */\n const transformedAction = options.actionTransformer(action);\n if (typeof transformedAction !== 'undefined' && transformedAction !== null) {\n scope.addBreadcrumb({\n category: ACTION_BREADCRUMB_CATEGORY,\n data: transformedAction,\n type: ACTION_BREADCRUMB_TYPE,\n });\n }\n\n /* Set latest state to scope */\n const transformedState = options.stateTransformer(newState);\n if (typeof transformedState !== 'undefined' && transformedState !== null) {\n scope.setContext(STATE_CONTEXT_KEY, transformedState);\n } else {\n scope.setContext(STATE_CONTEXT_KEY, null);\n }\n\n /* Allow user to configure scope with latest state */\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const { configureScopeWithState } = options;\n if (typeof configureScopeWithState === 'function') {\n configureScopeWithState(scope, newState);\n }\n });\n\n return newState;\n };\n\n return next(sentryReducer, initialState);\n };\n}\n\nexport { createReduxEnhancer };\n"]}
|
package/cjs/sdk.js
CHANGED
package/cjs/sdk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/sdk.ts"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/sdk.ts"],"names":[],"mappings":";AAAA,6CAAmF;AAEnF;;GAEG;AACH,SAAgB,IAAI,CAAC,OAAuB;IAC1C,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;IAC5C,OAAO,CAAC,SAAS,CAAC,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI;QAC/C,IAAI,EAAE,yBAAyB;QAC/B,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,mBAAmB;gBACzB,OAAO,EAAE,qBAAW;aACrB;SACF;QACD,OAAO,EAAE,qBAAW;KACrB,CAAC;IACF,cAAW,CAAC,OAAO,CAAC,CAAC;AACvB,CAAC;AAbD,oBAaC","sourcesContent":["import { BrowserOptions, init as browserInit, SDK_VERSION } from '@sentry/browser';\n\n/**\n * Inits the React SDK\n */\nexport function init(options: BrowserOptions): void {\n options._metadata = options._metadata || {};\n options._metadata.sdk = options._metadata.sdk || {\n name: 'sentry.javascript.react',\n packages: [\n {\n name: 'npm:@sentry/react',\n version: SDK_VERSION,\n },\n ],\n version: SDK_VERSION,\n };\n browserInit(options);\n}\n"]}
|
package/esm/constants.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export const REACT_RENDER_OP = 'ui.react.render';
|
|
2
|
+
export const REACT_UPDATE_OP = 'ui.react.update';
|
|
3
|
+
export const REACT_MOUNT_OP = 'ui.react.mount';
|
|
4
4
|
//# sourceMappingURL=constants.js.map
|
package/esm/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAEjD,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAEjD,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAC","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"]}
|
package/esm/errorboundary.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare type FallbackRender = (errorData: {
|
|
|
9
9
|
resetError(): void;
|
|
10
10
|
}) => React.ReactElement;
|
|
11
11
|
export declare type ErrorBoundaryProps = {
|
|
12
|
+
children?: React.ReactNode | (() => React.ReactNode);
|
|
12
13
|
/** If a Sentry report dialog should be rendered on error */
|
|
13
14
|
showDialog?: boolean;
|
|
14
15
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorboundary.d.ts","sourceRoot":"","sources":["../../src/errorboundary.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoB,mBAAmB,EAAE,KAAK,EAA+B,MAAM,iBAAiB,CAAC;AAG5G,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAGzD;AAED,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C,oBAAY,cAAc,GAAG,CAAC,SAAS,EAAE;IACvC,KAAK,EAAE,KAAK,CAAC;IACb,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,UAAU,IAAI,IAAI,CAAC;CACpB,KAAK,KAAK,CAAC,YAAY,CAAC;AAEzB,oBAAY,kBAAkB,GAAG;IAC/B,4DAA4D;IAC5D,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,aAAa,CAAC,EAAE,mBAAmB,CAAC;IACpC;;;;;;;OAOG;IACH,QA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AAS,iBAAiB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACtD,gBAAgB,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EACxC,oBAAoB,EAAE,kBAAkB,GACvC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAiBb;AAED,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,CAAC"}
|
package/esm/errorboundary.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { __assign, __extends } from "tslib";
|
|
2
1
|
import { captureException, showReportDialog, withScope } from '@sentry/browser';
|
|
3
2
|
import { logger } from '@sentry/utils';
|
|
4
3
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
5
4
|
import * as React from 'react';
|
|
6
5
|
import { IS_DEBUG_BUILD } from './flags';
|
|
7
6
|
export function isAtLeastReact17(version) {
|
|
8
|
-
|
|
7
|
+
const major = version.match(/^([^.]+)/);
|
|
9
8
|
return major !== null && parseInt(major[0]) >= 17;
|
|
10
9
|
}
|
|
11
|
-
export
|
|
12
|
-
|
|
10
|
+
export const UNKNOWN_COMPONENT = 'unknown';
|
|
11
|
+
const INITIAL_STATE = {
|
|
13
12
|
componentStack: null,
|
|
14
13
|
error: null,
|
|
15
14
|
eventId: null,
|
|
@@ -20,32 +19,28 @@ var INITIAL_STATE = {
|
|
|
20
19
|
* Sentry React SDK ErrorBoundary caught an error invoking your application code. This
|
|
21
20
|
* is expected behavior and NOT indicative of a bug with the Sentry React SDK.
|
|
22
21
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var _a = _this.state, error = _a.error, componentStack = _a.componentStack, eventId = _a.eventId;
|
|
22
|
+
class ErrorBoundary extends React.Component {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(...arguments);
|
|
25
|
+
this.state = INITIAL_STATE;
|
|
26
|
+
this.resetErrorBoundary = () => {
|
|
27
|
+
const { onReset } = this.props;
|
|
28
|
+
const { error, componentStack, eventId } = this.state;
|
|
31
29
|
if (onReset) {
|
|
32
30
|
onReset(error, componentStack, eventId);
|
|
33
31
|
}
|
|
34
|
-
|
|
32
|
+
this.setState(INITIAL_STATE);
|
|
35
33
|
};
|
|
36
|
-
return _this;
|
|
37
34
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var _b = this.props, beforeCapture = _b.beforeCapture, onError = _b.onError, showDialog = _b.showDialog, dialogOptions = _b.dialogOptions;
|
|
42
|
-
withScope(function (scope) {
|
|
35
|
+
componentDidCatch(error, { componentStack }) {
|
|
36
|
+
const { beforeCapture, onError, showDialog, dialogOptions } = this.props;
|
|
37
|
+
withScope(scope => {
|
|
43
38
|
// If on React version >= 17, create stack trace from componentStack param and links
|
|
44
39
|
// to to the original error using `error.cause` otherwise relies on error param for stacktrace.
|
|
45
40
|
// Linking errors requires the `LinkedErrors` integration be enabled.
|
|
46
41
|
if (isAtLeastReact17(React.version)) {
|
|
47
|
-
|
|
48
|
-
errorBoundaryError.name =
|
|
42
|
+
const errorBoundaryError = new Error(error.message);
|
|
43
|
+
errorBoundaryError.name = `React ErrorBoundary ${errorBoundaryError.name}`;
|
|
49
44
|
errorBoundaryError.stack = componentStack;
|
|
50
45
|
// Using the `LinkedErrors` integration to link the errors together.
|
|
51
46
|
error.cause = errorBoundaryError;
|
|
@@ -53,38 +48,38 @@ var ErrorBoundary = /** @class */ (function (_super) {
|
|
|
53
48
|
if (beforeCapture) {
|
|
54
49
|
beforeCapture(scope, error, componentStack);
|
|
55
50
|
}
|
|
56
|
-
|
|
51
|
+
const eventId = captureException(error, { contexts: { react: { componentStack } } });
|
|
57
52
|
if (onError) {
|
|
58
53
|
onError(error, componentStack, eventId);
|
|
59
54
|
}
|
|
60
55
|
if (showDialog) {
|
|
61
|
-
showReportDialog(
|
|
56
|
+
showReportDialog(Object.assign(Object.assign({}, dialogOptions), { eventId }));
|
|
62
57
|
}
|
|
63
58
|
// componentDidCatch is used over getDerivedStateFromError
|
|
64
59
|
// so that componentStack is accessible through state.
|
|
65
|
-
|
|
60
|
+
this.setState({ error, componentStack, eventId });
|
|
66
61
|
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
}
|
|
63
|
+
componentDidMount() {
|
|
64
|
+
const { onMount } = this.props;
|
|
70
65
|
if (onMount) {
|
|
71
66
|
onMount();
|
|
72
67
|
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
}
|
|
69
|
+
componentWillUnmount() {
|
|
70
|
+
const { error, componentStack, eventId } = this.state;
|
|
71
|
+
const { onUnmount } = this.props;
|
|
77
72
|
if (onUnmount) {
|
|
78
73
|
onUnmount(error, componentStack, eventId);
|
|
79
74
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
}
|
|
76
|
+
render() {
|
|
77
|
+
const { fallback, children } = this.props;
|
|
78
|
+
const { error, componentStack, eventId } = this.state;
|
|
84
79
|
if (error) {
|
|
85
|
-
|
|
80
|
+
let element = undefined;
|
|
86
81
|
if (typeof fallback === 'function') {
|
|
87
|
-
element = fallback({ error
|
|
82
|
+
element = fallback({ error, componentStack, resetError: this.resetErrorBoundary, eventId });
|
|
88
83
|
}
|
|
89
84
|
else {
|
|
90
85
|
element = fallback;
|
|
@@ -102,17 +97,16 @@ var ErrorBoundary = /** @class */ (function (_super) {
|
|
|
102
97
|
return children();
|
|
103
98
|
}
|
|
104
99
|
return children;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
}(React.Component));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
108
102
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
109
103
|
function withErrorBoundary(WrappedComponent, errorBoundaryOptions) {
|
|
110
104
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
React.createElement(WrappedComponent,
|
|
105
|
+
const componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;
|
|
106
|
+
const Wrapped = (props) => (React.createElement(ErrorBoundary, Object.assign({}, errorBoundaryOptions),
|
|
107
|
+
React.createElement(WrappedComponent, Object.assign({}, props))));
|
|
114
108
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
115
|
-
Wrapped.displayName =
|
|
109
|
+
Wrapped.displayName = `errorBoundary(${componentDisplayName})`;
|
|
116
110
|
// Copy over static methods from Wrapped component to Profiler HOC
|
|
117
111
|
// See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over
|
|
118
112
|
hoistNonReactStatics(Wrapped, WrappedComponent);
|
package/esm/errorboundary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorboundary.js","sourceRoot":"","sources":["../../src/errorboundary.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAA8B,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5G,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,IAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACxC,OAAO,KAAK,KAAK,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AACpD,CAAC;AAED,MAAM,CAAC,IAAM,iBAAiB,GAAG,SAAS,CAAC;AA4C3C,IAAM,aAAa,GAAG;IACpB,cAAc,EAAE,IAAI;IACpB,KAAK,EAAE,IAAI;IACX,OAAO,EAAE,IAAI;CAC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aAChF;YAED,0DAA0D;YAC1D,OAAO,IAAI,CAAC;SACb;QAED,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;YAClC,OAAO,QAAQ,EAAE,CAAC;SACnB;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACH,oBAAC;AAAD,CAAC,AAzFD,CAA4B,KAAK,CAAC,SAAS,GAyF1C;AAED,8DAA8D;AAC9D,SAAS,iBAAiB,CACxB,gBAAwC,EACxC,oBAAwC;IAExC,sEAAsE;IACtE,IAAM,oBAAoB,GAAG,gBAAgB,CAAC,WAAW,IAAI,gBAAgB,CAAC,IAAI,IAAI,iBAAiB,CAAC;IAExG,IAAM,OAAO,GAAgB,UAAC,KAAQ,IAAK,OAAA,CACzC,oBAAC,aAAa,eAAK,oBAAoB;QACrC,oBAAC,gBAAgB,eAAK,KAAK,EAAI,CACjB,CACjB,EAJ0C,CAI1C,CAAC;IAEF,sEAAsE;IACtE,OAAO,CAAC,WAAW,GAAG,mBAAiB,oBAAoB,MAAG,CAAC;IAE/D,kEAAkE;IAClE,gGAAgG;IAChG,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAChD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import { captureException, ReportDialogOptions, Scope, showReportDialog, withScope } from '@sentry/browser';\nimport { logger } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { IS_DEBUG_BUILD } from './flags';\n\nexport function isAtLeastReact17(version: string): boolean {\n const major = version.match(/^([^.]+)/);\n return major !== null && parseInt(major[0]) >= 17;\n}\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type FallbackRender = (errorData: {\n error: Error;\n componentStack: string | null;\n eventId: string | null;\n resetError(): void;\n}) => React.ReactElement;\n\nexport type ErrorBoundaryProps = {\n /** If a Sentry report dialog should be rendered on error */\n showDialog?: boolean;\n /**\n * Options to be passed into the Sentry report dialog.\n * No-op if {@link showDialog} is false.\n */\n dialogOptions?: ReportDialogOptions;\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;\n /** Called when the error boundary encounters an error */\n onError?(error: Error, componentStack: string, eventId: string): void;\n /** Called on componentDidMount() */\n onMount?(): void;\n /** Called if resetError() is called from the fallback render props function */\n onReset?(error: Error | null, componentStack: string | null, eventId: string | null): void;\n /** Called on componentWillUnmount() */\n onUnmount?(error: Error | null, componentStack: string | null, eventId: string | null): void;\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: Error | null, componentStack: string | null): void;\n};\n\ntype ErrorBoundaryState = {\n componentStack: React.ErrorInfo['componentStack'] | null;\n error: Error | null;\n eventId: string | null;\n};\n\nconst INITIAL_STATE = {\n componentStack: null,\n error: null,\n eventId: null,\n};\n\n/**\n * A ErrorBoundary component that logs errors to Sentry. Requires React >= 16.\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 = INITIAL_STATE;\n\n public componentDidCatch(error: Error & { cause?: Error }, { componentStack }: React.ErrorInfo): void {\n const { beforeCapture, onError, showDialog, dialogOptions } = this.props;\n\n withScope(scope => {\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 if (isAtLeastReact17(React.version)) {\n const errorBoundaryError = new Error(error.message);\n errorBoundaryError.name = `React ErrorBoundary ${errorBoundaryError.name}`;\n errorBoundaryError.stack = componentStack;\n\n // Using the `LinkedErrors` integration to link the errors together.\n error.cause = errorBoundaryError;\n }\n\n if (beforeCapture) {\n beforeCapture(scope, error, componentStack);\n }\n const eventId = captureException(error, { contexts: { react: { componentStack } } });\n if (onError) {\n onError(error, componentStack, eventId);\n }\n if (showDialog) {\n showReportDialog({ ...dialogOptions, eventId });\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 onUnmount(error, componentStack, eventId);\n }\n }\n\n public resetErrorBoundary: () => void = () => {\n const { onReset } = this.props;\n const { error, componentStack, eventId } = this.state;\n if (onReset) {\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 { error, componentStack, eventId } = this.state;\n\n if (error) {\n let element: React.ReactElement | undefined = undefined;\n if (typeof fallback === 'function') {\n element = fallback({ error, componentStack, resetError: this.resetErrorBoundary, eventId });\n } else {\n element = fallback;\n }\n\n if (React.isValidElement(element)) {\n return element;\n }\n\n if (fallback) {\n IS_DEBUG_BUILD && logger.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 if (typeof children === 'function') {\n return children();\n }\n return children;\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 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;\n\n const Wrapped: React.FC<P> = (props: P) => (\n <ErrorBoundary {...errorBoundaryOptions}>\n <WrappedComponent {...props} />\n </ErrorBoundary>\n );\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\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"]}
|
|
1
|
+
{"version":3,"file":"errorboundary.js","sourceRoot":"","sources":["../../src/errorboundary.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA8B,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5G,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACxC,OAAO,KAAK,KAAK,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AACpD,CAAC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC;AA6C3C,MAAM,aAAa,GAAG;IACpB,cAAc,EAAE,IAAI;IACpB,KAAK,EAAE,IAAI;IACX,OAAO,EAAE,IAAI;CACd,CAAC;AAEF;;;;;GAKG;AACH,MAAM,aAAc,SAAQ,KAAK,CAAC,SAAiD;IAAnF;;QACS,UAAK,GAAuB,aAAa,CAAC;QAkD1C,uBAAkB,GAAe,GAAG,EAAE;YAC3C,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAC/B,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,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;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAED,8DAA8D;AAC9D,SAAS,iBAAiB,CACxB,gBAAwC,EACxC,oBAAwC;IAExC,sEAAsE;IACtE,MAAM,oBAAoB,GAAG,gBAAgB,CAAC,WAAW,IAAI,gBAAgB,CAAC,IAAI,IAAI,iBAAiB,CAAC;IAExG,MAAM,OAAO,GAAgB,CAAC,KAAQ,EAAE,EAAE,CAAC,CACzC,oBAAC,aAAa,oBAAK,oBAAoB;QACrC,oBAAC,gBAAgB,oBAAK,KAAK,EAAI,CACjB,CACjB,CAAC;IAEF,sEAAsE;IACtE,OAAO,CAAC,WAAW,GAAG,iBAAiB,oBAAoB,GAAG,CAAC;IAE/D,kEAAkE;IAClE,gGAAgG;IAChG,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAChD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import { captureException, ReportDialogOptions, Scope, showReportDialog, withScope } from '@sentry/browser';\nimport { logger } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { IS_DEBUG_BUILD } from './flags';\n\nexport function isAtLeastReact17(version: string): boolean {\n const major = version.match(/^([^.]+)/);\n return major !== null && parseInt(major[0]) >= 17;\n}\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type FallbackRender = (errorData: {\n error: Error;\n componentStack: string | null;\n eventId: string | null;\n resetError(): void;\n}) => React.ReactElement;\n\nexport type ErrorBoundaryProps = {\n children?: React.ReactNode | (() => React.ReactNode);\n /** If a Sentry report dialog should be rendered on error */\n showDialog?: boolean;\n /**\n * Options to be passed into the Sentry report dialog.\n * No-op if {@link showDialog} is false.\n */\n dialogOptions?: ReportDialogOptions;\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;\n /** Called when the error boundary encounters an error */\n onError?(error: Error, componentStack: string, eventId: string): void;\n /** Called on componentDidMount() */\n onMount?(): void;\n /** Called if resetError() is called from the fallback render props function */\n onReset?(error: Error | null, componentStack: string | null, eventId: string | null): void;\n /** Called on componentWillUnmount() */\n onUnmount?(error: Error | null, componentStack: string | null, eventId: string | null): void;\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: Error | null, componentStack: string | null): void;\n};\n\ntype ErrorBoundaryState = {\n componentStack: React.ErrorInfo['componentStack'] | null;\n error: Error | null;\n eventId: string | null;\n};\n\nconst INITIAL_STATE = {\n componentStack: null,\n error: null,\n eventId: null,\n};\n\n/**\n * A ErrorBoundary component that logs errors to Sentry. Requires React >= 16.\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 = INITIAL_STATE;\n\n public componentDidCatch(error: Error & { cause?: Error }, { componentStack }: React.ErrorInfo): void {\n const { beforeCapture, onError, showDialog, dialogOptions } = this.props;\n\n withScope(scope => {\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 if (isAtLeastReact17(React.version)) {\n const errorBoundaryError = new Error(error.message);\n errorBoundaryError.name = `React ErrorBoundary ${errorBoundaryError.name}`;\n errorBoundaryError.stack = componentStack;\n\n // Using the `LinkedErrors` integration to link the errors together.\n error.cause = errorBoundaryError;\n }\n\n if (beforeCapture) {\n beforeCapture(scope, error, componentStack);\n }\n const eventId = captureException(error, { contexts: { react: { componentStack } } });\n if (onError) {\n onError(error, componentStack, eventId);\n }\n if (showDialog) {\n showReportDialog({ ...dialogOptions, eventId });\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 onUnmount(error, componentStack, eventId);\n }\n }\n\n public resetErrorBoundary: () => void = () => {\n const { onReset } = this.props;\n const { error, componentStack, eventId } = this.state;\n if (onReset) {\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 { error, componentStack, eventId } = this.state;\n\n if (error) {\n let element: React.ReactElement | undefined = undefined;\n if (typeof fallback === 'function') {\n element = fallback({ error, componentStack, resetError: this.resetErrorBoundary, eventId });\n } else {\n element = fallback;\n }\n\n if (React.isValidElement(element)) {\n return element;\n }\n\n if (fallback) {\n IS_DEBUG_BUILD && logger.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 if (typeof children === 'function') {\n return (children as () => React.ReactNode)();\n }\n return children;\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 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;\n\n const Wrapped: React.FC<P> = (props: P) => (\n <ErrorBoundary {...errorBoundaryOptions}>\n <WrappedComponent {...props} />\n </ErrorBoundary>\n );\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\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"]}
|
package/esm/flags.js
CHANGED
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
* replaced.
|
|
13
13
|
*/
|
|
14
14
|
/** Flag that is true for debug builds, false otherwise. */
|
|
15
|
-
export
|
|
15
|
+
export const IS_DEBUG_BUILD = typeof __SENTRY_DEBUG__ === 'undefined' ? true : __SENTRY_DEBUG__;
|
|
16
16
|
//# sourceMappingURL=flags.js.map
|
package/esm/flags.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flags.js","sourceRoot":"","sources":["../../src/flags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,2DAA2D;AAC3D,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"flags.js","sourceRoot":"","sources":["../../src/flags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,2DAA2D;AAC3D,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,gBAAgB,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC","sourcesContent":["/*\n * This file defines flags and constants that can be modified during compile time in order to facilitate tree shaking\n * for users.\n *\n * Debug flags need to be declared in each package individually and must not be imported across package boundaries,\n * because some build tools have trouble tree-shaking imported guards.\n *\n * As a convention, we define debug flags in a `flags.ts` file in the root of a package's `src` folder.\n *\n * Debug flag files will contain \"magic strings\" like `__SENTRY_DEBUG__` that may get replaced with actual values during\n * our, or the user's build process. Take care when introducing new flags - they must not throw if they are not\n * replaced.\n */\n\ndeclare const __SENTRY_DEBUG__: boolean;\n\n/** Flag that is true for debug builds, false otherwise. */\nexport const IS_DEBUG_BUILD = typeof __SENTRY_DEBUG__ === 'undefined' ? true : __SENTRY_DEBUG__;\n"]}
|