@sentry/react
Advanced tools
Comparing version 7.95.0 to 7.97.0
@@ -38,2 +38,3 @@ Object.defineProperty(exports, '__esModule', { value: true }); | ||
let _startTransactionOnLocationChange; | ||
let _stripBasename = false; | ||
@@ -50,2 +51,3 @@ const SENTRY_TAGS = { | ||
matchRoutes, | ||
stripBasename, | ||
) { | ||
@@ -75,2 +77,3 @@ return ( | ||
_createRoutesFromChildren = createRoutesFromChildren; | ||
_stripBasename = stripBasename || false; | ||
@@ -82,2 +85,29 @@ _customStartTransaction = customStartTransaction; | ||
/** | ||
* Strip the basename from a pathname if exists. | ||
* | ||
* Vendored and modified from `react-router` | ||
* https://github.com/remix-run/react-router/blob/462bb712156a3f739d6139a0f14810b76b002df6/packages/router/utils.ts#L1038 | ||
*/ | ||
function stripBasenameFromPathname(pathname, basename) { | ||
if (!basename || basename === '/') { | ||
return pathname; | ||
} | ||
if (!pathname.toLowerCase().startsWith(basename.toLowerCase())) { | ||
return pathname; | ||
} | ||
// We want to leave trailing slash behavior in the user's control, so if they | ||
// specify a basename with a trailing slash, we should support it | ||
const startIndex = basename.endsWith('/') ? basename.length - 1 : basename.length; | ||
const nextChar = pathname.charAt(startIndex); | ||
if (nextChar && nextChar !== '/') { | ||
// pathname does not start with basename/ | ||
return pathname; | ||
} | ||
return pathname.slice(startIndex) || '/'; | ||
} | ||
function getNormalizedName( | ||
@@ -90,3 +120,3 @@ routes, | ||
if (!routes || routes.length === 0) { | ||
return [location.pathname, 'url']; | ||
return [_stripBasename ? stripBasenameFromPathname(location.pathname, basename) : location.pathname, 'url']; | ||
} | ||
@@ -103,3 +133,3 @@ | ||
if (route.index) { | ||
return [branch.pathname, 'route']; | ||
return [_stripBasename ? stripBasenameFromPathname(branch.pathname, basename) : branch.pathname, 'route']; | ||
} | ||
@@ -121,5 +151,5 @@ | ||
) { | ||
return [basename + newPath, 'route']; | ||
return [(_stripBasename ? '' : basename) + newPath, 'route']; | ||
} | ||
return [basename + pathBuilder, 'route']; | ||
return [(_stripBasename ? '' : basename) + pathBuilder, 'route']; | ||
} | ||
@@ -131,3 +161,3 @@ } | ||
return [location.pathname, 'url']; | ||
return [_stripBasename ? stripBasenameFromPathname(location.pathname, basename) : location.pathname, 'url']; | ||
} | ||
@@ -221,3 +251,3 @@ | ||
// will break advanced type inference done by react router params | ||
return React__namespace.createElement(Routes, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 213}} ); | ||
return React__namespace.createElement(Routes, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 243}} ); | ||
}; | ||
@@ -277,3 +307,3 @@ | ||
return (routes, locationArg) => { | ||
return React__namespace.createElement(SentryRoutes, { routes: routes, locationArg: locationArg, __self: this, __source: {fileName: _jsxFileName, lineNumber: 270}} ); | ||
return React__namespace.createElement(SentryRoutes, { routes: routes, locationArg: locationArg, __self: this, __source: {fileName: _jsxFileName, lineNumber: 300}} ); | ||
}; | ||
@@ -280,0 +310,0 @@ } |
@@ -19,2 +19,3 @@ import { WINDOW } from '@sentry/browser'; | ||
let _startTransactionOnLocationChange; | ||
let _stripBasename = false; | ||
@@ -31,2 +32,3 @@ const SENTRY_TAGS = { | ||
matchRoutes, | ||
stripBasename, | ||
) { | ||
@@ -56,2 +58,3 @@ return ( | ||
_createRoutesFromChildren = createRoutesFromChildren; | ||
_stripBasename = stripBasename || false; | ||
@@ -63,2 +66,29 @@ _customStartTransaction = customStartTransaction; | ||
/** | ||
* Strip the basename from a pathname if exists. | ||
* | ||
* Vendored and modified from `react-router` | ||
* https://github.com/remix-run/react-router/blob/462bb712156a3f739d6139a0f14810b76b002df6/packages/router/utils.ts#L1038 | ||
*/ | ||
function stripBasenameFromPathname(pathname, basename) { | ||
if (!basename || basename === '/') { | ||
return pathname; | ||
} | ||
if (!pathname.toLowerCase().startsWith(basename.toLowerCase())) { | ||
return pathname; | ||
} | ||
// We want to leave trailing slash behavior in the user's control, so if they | ||
// specify a basename with a trailing slash, we should support it | ||
const startIndex = basename.endsWith('/') ? basename.length - 1 : basename.length; | ||
const nextChar = pathname.charAt(startIndex); | ||
if (nextChar && nextChar !== '/') { | ||
// pathname does not start with basename/ | ||
return pathname; | ||
} | ||
return pathname.slice(startIndex) || '/'; | ||
} | ||
function getNormalizedName( | ||
@@ -71,3 +101,3 @@ routes, | ||
if (!routes || routes.length === 0) { | ||
return [location.pathname, 'url']; | ||
return [_stripBasename ? stripBasenameFromPathname(location.pathname, basename) : location.pathname, 'url']; | ||
} | ||
@@ -84,3 +114,3 @@ | ||
if (route.index) { | ||
return [branch.pathname, 'route']; | ||
return [_stripBasename ? stripBasenameFromPathname(branch.pathname, basename) : branch.pathname, 'route']; | ||
} | ||
@@ -102,5 +132,5 @@ | ||
) { | ||
return [basename + newPath, 'route']; | ||
return [(_stripBasename ? '' : basename) + newPath, 'route']; | ||
} | ||
return [basename + pathBuilder, 'route']; | ||
return [(_stripBasename ? '' : basename) + pathBuilder, 'route']; | ||
} | ||
@@ -112,3 +142,3 @@ } | ||
return [location.pathname, 'url']; | ||
return [_stripBasename ? stripBasenameFromPathname(location.pathname, basename) : location.pathname, 'url']; | ||
} | ||
@@ -202,3 +232,3 @@ | ||
// will break advanced type inference done by react router params | ||
return React.createElement(Routes, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 213}} ); | ||
return React.createElement(Routes, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 243}} ); | ||
}; | ||
@@ -258,3 +288,3 @@ | ||
return (routes, locationArg) => { | ||
return React.createElement(SentryRoutes, { routes: routes, locationArg: locationArg, __self: this, __source: {fileName: _jsxFileName, lineNumber: 270}} ); | ||
return React.createElement(SentryRoutes, { routes: routes, locationArg: locationArg, __self: this, __source: {fileName: _jsxFileName, lineNumber: 300}} ); | ||
}; | ||
@@ -261,0 +291,0 @@ } |
{ | ||
"name": "@sentry/react", | ||
"version": "7.95.0", | ||
"version": "7.97.0", | ||
"description": "Official Sentry SDK for React.js", | ||
@@ -32,6 +32,6 @@ "repository": "git://github.com/getsentry/sentry-javascript.git", | ||
"dependencies": { | ||
"@sentry/browser": "7.95.0", | ||
"@sentry/core": "7.95.0", | ||
"@sentry/types": "7.95.0", | ||
"@sentry/utils": "7.95.0", | ||
"@sentry/browser": "7.97.0", | ||
"@sentry/core": "7.97.0", | ||
"@sentry/types": "7.97.0", | ||
"@sentry/utils": "7.97.0", | ||
"hoist-non-react-statics": "^3.3.2" | ||
@@ -38,0 +38,0 @@ }, |
import { Transaction, TransactionContext } from '@sentry/types'; | ||
import * as React from 'react'; | ||
import { CreateRouterFunction, CreateRoutesFromChildren, MatchRoutes, Router, RouterState, UseEffect, UseLocation, UseNavigationType, UseRoutes } from './types'; | ||
export declare function reactRouterV6Instrumentation(useEffect: UseEffect, useLocation: UseLocation, useNavigationType: UseNavigationType, createRoutesFromChildren: CreateRoutesFromChildren, matchRoutes: MatchRoutes): (customStartTransaction: (context: TransactionContext) => Transaction | undefined, startTransactionOnPageLoad?: boolean, startTransactionOnLocationChange?: boolean) => void; | ||
export declare function reactRouterV6Instrumentation(useEffect: UseEffect, useLocation: UseLocation, useNavigationType: UseNavigationType, createRoutesFromChildren: CreateRoutesFromChildren, matchRoutes: MatchRoutes, stripBasename?: boolean): (customStartTransaction: (context: TransactionContext) => Transaction | undefined, startTransactionOnPageLoad?: boolean, startTransactionOnLocationChange?: boolean) => void; | ||
export declare function withSentryReactRouterV6Routing<P extends Record<string, any>, R extends React.FC<P>>(Routes: R): R; | ||
@@ -6,0 +6,0 @@ export declare function wrapUseRoutes(origUseRoutes: UseRoutes): UseRoutes; |
import type { Transaction, TransactionContext } from '@sentry/types'; | ||
import * as React from 'react'; | ||
import type { CreateRouterFunction, CreateRoutesFromChildren, MatchRoutes, Router, RouterState, UseEffect, UseLocation, UseNavigationType, UseRoutes } from './types'; | ||
export declare function reactRouterV6Instrumentation(useEffect: UseEffect, useLocation: UseLocation, useNavigationType: UseNavigationType, createRoutesFromChildren: CreateRoutesFromChildren, matchRoutes: MatchRoutes): (customStartTransaction: (context: TransactionContext) => Transaction | undefined, startTransactionOnPageLoad?: boolean, startTransactionOnLocationChange?: boolean) => void; | ||
export declare function reactRouterV6Instrumentation(useEffect: UseEffect, useLocation: UseLocation, useNavigationType: UseNavigationType, createRoutesFromChildren: CreateRoutesFromChildren, matchRoutes: MatchRoutes, stripBasename?: boolean): (customStartTransaction: (context: TransactionContext) => Transaction | undefined, startTransactionOnPageLoad?: boolean, startTransactionOnLocationChange?: boolean) => void; | ||
export declare function withSentryReactRouterV6Routing<P extends Record<string, any>, R extends React.FC<P>>(Routes: R): R; | ||
@@ -6,0 +6,0 @@ export declare function wrapUseRoutes(origUseRoutes: UseRoutes): UseRoutes; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
286854
2934
+ Added@sentry-internal/feedback@7.97.0(transitive)
+ Added@sentry-internal/replay-canvas@7.97.0(transitive)
+ Added@sentry-internal/tracing@7.97.0(transitive)
+ Added@sentry/browser@7.97.0(transitive)
+ Added@sentry/core@7.97.0(transitive)
+ Added@sentry/replay@7.97.0(transitive)
+ Added@sentry/types@7.97.0(transitive)
+ Added@sentry/utils@7.97.0(transitive)
- Removed@sentry-internal/feedback@7.95.0(transitive)
- Removed@sentry-internal/replay-canvas@7.95.0(transitive)
- Removed@sentry-internal/tracing@7.95.0(transitive)
- Removed@sentry/browser@7.95.0(transitive)
- Removed@sentry/core@7.95.0(transitive)
- Removed@sentry/replay@7.95.0(transitive)
- Removed@sentry/types@7.95.0(transitive)
- Removed@sentry/utils@7.95.0(transitive)
Updated@sentry/browser@7.97.0
Updated@sentry/core@7.97.0
Updated@sentry/types@7.97.0
Updated@sentry/utils@7.97.0