Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core/utils): Deprecate getNumberOfUrlSegments #14458

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/migration/draft-v9-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Deprecated `extractRequestData`. Instead manually extract relevant data off request.
- Deprecated `arrayify`. No replacements.
- Deprecated `memoBuilder`. No replacements.
- Deprecated `getNumberOfUrlSegments`. No replacements.
- Deprecated `BAGGAGE_HEADER_NAME`. No replacements.
- Deprecated `makeFifoCache`. No replacements.

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils-hoist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export {
parseBaggageHeader,
} from './baggage';

// eslint-disable-next-line deprecation/deprecation
export { getNumberOfUrlSegments, getSanitizedUrlString, parseUrl, stripUrlQueryAndFragment } from './url';
// eslint-disable-next-line deprecation/deprecation
export { makeFifoCache } from './cache';
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/utils-hoist/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ export function stripUrlQueryAndFragment(urlPath: string): string {

/**
* Returns number of URL segments of a passed string URL.
*
* @deprecated This function will be removed in the next major version.
*/
// TODO(v9): Hoist this function into the places where we use it. (as it stands only react router v6 instrumentation)
export function getNumberOfUrlSegments(url: string): number {
// split at '/' or at '\/' to split regex urls correctly
return url.split(/\\?\//).filter(s => s.length > 0 && s !== ',').length;
Expand Down
1 change: 1 addition & 0 deletions packages/core/test/utils-hoist/url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('getNumberOfUrlSegments', () => {
['multi param parameterized path', '/stores/:storeId/products/:productId', 4],
['regex path', String(/\/api\/post[0-9]/), 2],
])('%s', (_: string, input, output) => {
// eslint-disable-next-line deprecation/deprecation
expect(getNumberOfUrlSegments(input)).toEqual(output);
});
});
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/reactrouterv6.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ function getNormalizedName(
// If the route defined on the element is something like
// <Route path="/stores/:storeId/products/:productId" element={<div>Product</div>} />
// We should check against the branch.pathname for the number of / separators
// TODO(v9): Put the implementation of `getNumberOfUrlSegments` in this file
// eslint-disable-next-line deprecation/deprecation
getNumberOfUrlSegments(pathBuilder) !== getNumberOfUrlSegments(branch.pathname) &&
// We should not count wildcard operators in the url segments calculation
pathBuilder.slice(-2) !== '/*'
Expand Down
1 change: 1 addition & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ export const _optionalChainDelete = _optionalChainDelete_imported;
export const BAGGAGE_HEADER_NAME = BAGGAGE_HEADER_NAME_imported;

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

/** @deprecated Import from `@sentry/core` instead. */
Expand Down
Loading