Skip to content

Commit 91a4985

Browse files
authored
feat(core/utils): Deprecate getNumberOfUrlSegments (#14458)
1 parent fc1d986 commit 91a4985

File tree

6 files changed

+9
-0
lines changed

6 files changed

+9
-0
lines changed

docs/migration/draft-v9-migration-guide.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ If you are relying on `undefined` being passed in and having tracing enabled bec
3131
- Deprecated `extractRequestData`. Instead manually extract relevant data off request.
3232
- Deprecated `arrayify`. No replacements.
3333
- Deprecated `memoBuilder`. No replacements.
34+
- Deprecated `getNumberOfUrlSegments`. No replacements.
3435
- Deprecated `BAGGAGE_HEADER_NAME`. No replacements.
3536
- Deprecated `makeFifoCache`. No replacements.
3637
- Deprecated `flatten`. No replacements.

packages/core/src/utils-hoist/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export {
159159
parseBaggageHeader,
160160
} from './baggage';
161161

162+
// eslint-disable-next-line deprecation/deprecation
162163
export { getNumberOfUrlSegments, getSanitizedUrlString, parseUrl, stripUrlQueryAndFragment } from './url';
163164
// eslint-disable-next-line deprecation/deprecation
164165
export { makeFifoCache } from './cache';

packages/core/src/utils-hoist/url.ts

+3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ export function stripUrlQueryAndFragment(urlPath: string): string {
5050

5151
/**
5252
* Returns number of URL segments of a passed string URL.
53+
*
54+
* @deprecated This function will be removed in the next major version.
5355
*/
56+
// TODO(v9): Hoist this function into the places where we use it. (as it stands only react router v6 instrumentation)
5457
export function getNumberOfUrlSegments(url: string): number {
5558
// split at '/' or at '\/' to split regex urls correctly
5659
return url.split(/\\?\//).filter(s => s.length > 0 && s !== ',').length;

packages/core/test/utils-hoist/url.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe('getNumberOfUrlSegments', () => {
3333
['multi param parameterized path', '/stores/:storeId/products/:productId', 4],
3434
['regex path', String(/\/api\/post[0-9]/), 2],
3535
])('%s', (_: string, input, output) => {
36+
// eslint-disable-next-line deprecation/deprecation
3637
expect(getNumberOfUrlSegments(input)).toEqual(output);
3738
});
3839
});

packages/react/src/reactrouterv6.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ function getNormalizedName(
197197
// If the route defined on the element is something like
198198
// <Route path="/stores/:storeId/products/:productId" element={<div>Product</div>} />
199199
// We should check against the branch.pathname for the number of / separators
200+
// TODO(v9): Put the implementation of `getNumberOfUrlSegments` in this file
201+
// eslint-disable-next-line deprecation/deprecation
200202
getNumberOfUrlSegments(pathBuilder) !== getNumberOfUrlSegments(branch.pathname) &&
201203
// We should not count wildcard operators in the url segments calculation
202204
pathBuilder.slice(-2) !== '/*'

packages/utils/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ export const _optionalChainDelete = _optionalChainDelete_imported;
666666
export const BAGGAGE_HEADER_NAME = BAGGAGE_HEADER_NAME_imported;
667667

668668
/** @deprecated Import from `@sentry/core` instead. */
669+
// eslint-disable-next-line deprecation/deprecation
669670
export const getNumberOfUrlSegments = getNumberOfUrlSegments_imported;
670671

671672
/** @deprecated Import from `@sentry/core` instead. */

0 commit comments

Comments
 (0)