Skip to content

Commit 1bff156

Browse files
committed
Add missing local exports
1 parent 0e85f9b commit 1bff156

File tree

4 files changed

+39
-30
lines changed

4 files changed

+39
-30
lines changed

packages/react/src/reactrouter-compat-utils/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export {
1010
handleExistingNavigationSpan,
1111
createNewNavigationSpan,
1212
addResolvedRoutesToParent,
13+
processResolvedRoutes,
1314
} from './instrumentation';
1415

1516
// Utility exports
@@ -19,6 +20,7 @@ export {
1920
rebuildRoutePathFromAllRoutes,
2021
locationIsInsideDescendantRoute,
2122
getNormalizedName,
23+
getNumberOfUrlSegments,
2224
resolveRouteNameAndSource,
2325
pathEndsWithWildcard,
2426
pathIsWildcardAndHasChildren,

packages/react/src/reactrouter-compat-utils/instrumentation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const allRoutes = new Set<RouteObject>();
114114
/**
115115
* Processes resolved routes by adding them to allRoutes and checking for nested async handlers.
116116
*/
117-
function processResolvedRoutes(
117+
export function processResolvedRoutes(
118118
resolvedRoutes: RouteObject[],
119119
parentRoute?: RouteObject,
120120
currentLocation?: Location,

packages/react/src/reactrouter-compat-utils/utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@ function sendIndexPath(pathBuilder: string, pathname: string, basename: string):
6464
return [formattedPath, 'route'];
6565
}
6666

67-
function getNumberOfUrlSegments(url: string): number {
67+
/**
68+
* Returns the number of URL segments in the given URL string.
69+
* Splits at '/' or '\/' to handle regex URLs correctly.
70+
*
71+
* @param url - The URL string to segment.
72+
* @returns The number of segments in the URL.
73+
*/
74+
export function getNumberOfUrlSegments(url: string): number {
6875
// split at '/' or at '\/' to split regex urls correctly
6976
return url.split(/\\?\//).filter(s => s.length > 0 && s !== ',').length;
7077
}

packages/react/test/reactrouterv6-compat-utils.test.tsx

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { describe, expect, it, test } from 'vitest';
2-
import { checkRouteForAsyncHandler } from '../src/lazy-route-utils';
3-
import { getNumberOfUrlSegments } from '../src/reactrouterv6-compat-utils';
2+
import {
3+
checkRouteForAsyncHandler,
4+
getNumberOfUrlSegments,
5+
processResolvedRoutes,
6+
} from '../src/reactrouter-compat-utils';
47
import type { RouteObject } from '../src/types';
58

6-
// Mock processResolvedRoutes function for tests
7-
const mockProcessResolvedRoutes = () => {};
8-
99
describe('getNumberOfUrlSegments', () => {
1010
test.each([
1111
['regular path', '/projects/123/views/234', 4],
@@ -27,8 +27,8 @@ describe('checkRouteForAsyncHandler', () => {
2727
},
2828
};
2929

30-
checkRouteForAsyncHandler(route, mockProcessResolvedRoutes);
31-
checkRouteForAsyncHandler(route, mockProcessResolvedRoutes);
30+
checkRouteForAsyncHandler(route, processResolvedRoutes);
31+
checkRouteForAsyncHandler(route, processResolvedRoutes);
3232

3333
const proxiedHandler = route.handle?.lazyChildren;
3434
expect(typeof proxiedHandler).toBe('function');
@@ -45,7 +45,7 @@ describe('checkRouteForAsyncHandler', () => {
4545
path: '/test',
4646
};
4747

48-
expect(() => checkRouteForAsyncHandler(route, mockProcessResolvedRoutes)).not.toThrow();
48+
expect(() => checkRouteForAsyncHandler(route, processResolvedRoutes)).not.toThrow();
4949
});
5050

5151
it('should handle routes with non-function handle properties', () => {
@@ -56,7 +56,7 @@ describe('checkRouteForAsyncHandler', () => {
5656
},
5757
};
5858

59-
expect(() => checkRouteForAsyncHandler(route, mockProcessResolvedRoutes)).not.toThrow();
59+
expect(() => checkRouteForAsyncHandler(route, processResolvedRoutes)).not.toThrow();
6060
});
6161

6262
it('should handle routes with null/undefined handle properties', () => {
@@ -65,7 +65,7 @@ describe('checkRouteForAsyncHandler', () => {
6565
handle: null as any,
6666
};
6767

68-
expect(() => checkRouteForAsyncHandler(route, mockProcessResolvedRoutes)).not.toThrow();
68+
expect(() => checkRouteForAsyncHandler(route, processResolvedRoutes)).not.toThrow();
6969
});
7070

7171
it('should handle routes with mixed function and non-function handle properties', () => {
@@ -79,7 +79,7 @@ describe('checkRouteForAsyncHandler', () => {
7979
},
8080
};
8181

82-
checkRouteForAsyncHandler(route, mockProcessResolvedRoutes);
82+
checkRouteForAsyncHandler(route, processResolvedRoutes);
8383

8484
const proxiedHandler = route.handle?.lazyChildren;
8585
expect(typeof proxiedHandler).toBe('function');
@@ -110,7 +110,7 @@ describe('checkRouteForAsyncHandler', () => {
110110
],
111111
};
112112

113-
checkRouteForAsyncHandler(route, mockProcessResolvedRoutes);
113+
checkRouteForAsyncHandler(route, processResolvedRoutes);
114114

115115
// Check parent handler is proxied
116116
const proxiedParentHandler = route.handle?.lazyChildren;
@@ -153,7 +153,7 @@ describe('checkRouteForAsyncHandler', () => {
153153
],
154154
};
155155

156-
checkRouteForAsyncHandler(route, mockProcessResolvedRoutes);
156+
checkRouteForAsyncHandler(route, processResolvedRoutes);
157157

158158
// Check all handlers are proxied
159159
expect((route.handle?.lazyChildren as { __sentry_proxied__?: boolean }).__sentry_proxied__).toBe(true);
@@ -179,7 +179,7 @@ describe('checkRouteForAsyncHandler', () => {
179179
},
180180
};
181181

182-
checkRouteForAsyncHandler(route, mockProcessResolvedRoutes);
182+
checkRouteForAsyncHandler(route, processResolvedRoutes);
183183

184184
// Check all handlers are proxied
185185
expect((route.handle?.lazyChildren as { __sentry_proxied__?: boolean }).__sentry_proxied__).toBe(true);
@@ -197,13 +197,13 @@ describe('checkRouteForAsyncHandler', () => {
197197
};
198198

199199
// First call should proxy the function
200-
checkRouteForAsyncHandler(route, mockProcessResolvedRoutes);
200+
checkRouteForAsyncHandler(route, processResolvedRoutes);
201201
const firstProxiedHandler = route.handle?.lazyChildren;
202202
expect(firstProxiedHandler).not.toBe(mockHandler);
203203
expect((firstProxiedHandler as { __sentry_proxied__?: boolean }).__sentry_proxied__).toBe(true);
204204

205205
// Second call should not create a new proxy
206-
checkRouteForAsyncHandler(route, mockProcessResolvedRoutes);
206+
checkRouteForAsyncHandler(route, processResolvedRoutes);
207207
const secondProxiedHandler = route.handle?.lazyChildren;
208208
expect(secondProxiedHandler).toBe(firstProxiedHandler); // Should be the same proxy
209209
expect((secondProxiedHandler as { __sentry_proxied__?: boolean }).__sentry_proxied__).toBe(true);
@@ -215,7 +215,7 @@ describe('checkRouteForAsyncHandler', () => {
215215
children: [],
216216
};
217217

218-
expect(() => checkRouteForAsyncHandler(route, mockProcessResolvedRoutes)).not.toThrow();
218+
expect(() => checkRouteForAsyncHandler(route, processResolvedRoutes)).not.toThrow();
219219
});
220220

221221
it('should handle routes with undefined children', () => {
@@ -224,7 +224,7 @@ describe('checkRouteForAsyncHandler', () => {
224224
children: undefined,
225225
};
226226

227-
expect(() => checkRouteForAsyncHandler(route, mockProcessResolvedRoutes)).not.toThrow();
227+
expect(() => checkRouteForAsyncHandler(route, processResolvedRoutes)).not.toThrow();
228228
});
229229

230230
it('should handle routes with null children', () => {
@@ -233,7 +233,7 @@ describe('checkRouteForAsyncHandler', () => {
233233
children: null as any,
234234
};
235235

236-
expect(() => checkRouteForAsyncHandler(route, mockProcessResolvedRoutes)).not.toThrow();
236+
expect(() => checkRouteForAsyncHandler(route, processResolvedRoutes)).not.toThrow();
237237
});
238238

239239
it('should handle routes with non-array children', () => {
@@ -242,7 +242,7 @@ describe('checkRouteForAsyncHandler', () => {
242242
children: 'not an array' as any,
243243
};
244244

245-
expect(() => checkRouteForAsyncHandler(route, mockProcessResolvedRoutes)).not.toThrow();
245+
expect(() => checkRouteForAsyncHandler(route, processResolvedRoutes)).not.toThrow();
246246
});
247247

248248
it('should handle routes with handle that is not an object', () => {
@@ -251,7 +251,7 @@ describe('checkRouteForAsyncHandler', () => {
251251
handle: 'not an object' as any,
252252
};
253253

254-
expect(() => checkRouteForAsyncHandler(route, mockProcessResolvedRoutes)).not.toThrow();
254+
expect(() => checkRouteForAsyncHandler(route, processResolvedRoutes)).not.toThrow();
255255
});
256256

257257
it('should handle routes with handle that is null', () => {
@@ -260,7 +260,7 @@ describe('checkRouteForAsyncHandler', () => {
260260
handle: null as any,
261261
};
262262

263-
expect(() => checkRouteForAsyncHandler(route, mockProcessResolvedRoutes)).not.toThrow();
263+
expect(() => checkRouteForAsyncHandler(route, processResolvedRoutes)).not.toThrow();
264264
});
265265

266266
it('should handle routes with handle that is undefined', () => {
@@ -269,7 +269,7 @@ describe('checkRouteForAsyncHandler', () => {
269269
handle: undefined as any,
270270
};
271271

272-
expect(() => checkRouteForAsyncHandler(route, mockProcessResolvedRoutes)).not.toThrow();
272+
expect(() => checkRouteForAsyncHandler(route, processResolvedRoutes)).not.toThrow();
273273
});
274274

275275
it('should handle routes with handle that is a function', () => {
@@ -278,7 +278,7 @@ describe('checkRouteForAsyncHandler', () => {
278278
handle: (() => {}) as any,
279279
};
280280

281-
expect(() => checkRouteForAsyncHandler(route, mockProcessResolvedRoutes)).not.toThrow();
281+
expect(() => checkRouteForAsyncHandler(route, processResolvedRoutes)).not.toThrow();
282282
});
283283

284284
it('should handle routes with handle that is a string', () => {
@@ -287,7 +287,7 @@ describe('checkRouteForAsyncHandler', () => {
287287
handle: 'string handle' as any,
288288
};
289289

290-
expect(() => checkRouteForAsyncHandler(route, mockProcessResolvedRoutes)).not.toThrow();
290+
expect(() => checkRouteForAsyncHandler(route, processResolvedRoutes)).not.toThrow();
291291
});
292292

293293
it('should handle routes with handle that is a number', () => {
@@ -296,7 +296,7 @@ describe('checkRouteForAsyncHandler', () => {
296296
handle: 42 as any,
297297
};
298298

299-
expect(() => checkRouteForAsyncHandler(route, mockProcessResolvedRoutes)).not.toThrow();
299+
expect(() => checkRouteForAsyncHandler(route, processResolvedRoutes)).not.toThrow();
300300
});
301301

302302
it('should handle routes with handle that is a boolean', () => {
@@ -305,7 +305,7 @@ describe('checkRouteForAsyncHandler', () => {
305305
handle: true as any,
306306
};
307307

308-
expect(() => checkRouteForAsyncHandler(route, mockProcessResolvedRoutes)).not.toThrow();
308+
expect(() => checkRouteForAsyncHandler(route, processResolvedRoutes)).not.toThrow();
309309
});
310310

311311
it('should handle routes with handle that is an array', () => {
@@ -314,6 +314,6 @@ describe('checkRouteForAsyncHandler', () => {
314314
handle: [] as any,
315315
};
316316

317-
expect(() => checkRouteForAsyncHandler(route, mockProcessResolvedRoutes)).not.toThrow();
317+
expect(() => checkRouteForAsyncHandler(route, processResolvedRoutes)).not.toThrow();
318318
});
319319
});

0 commit comments

Comments
 (0)