Skip to content

Commit 44ad37c

Browse files
ci: apply automated fixes
1 parent b4d41f8 commit 44ad37c

File tree

9 files changed

+236
-180
lines changed

9 files changed

+236
-180
lines changed

packages/react-router/src/link.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,16 @@ export function useLinkProps<
104104
select: (match) => match.index,
105105
})
106106

107-
const getFrom = React.useCallback( () => {
108-
const currentRouteMatches= router.matchRoutes(router.latestLocation, {
107+
const getFrom = React.useCallback(() => {
108+
const currentRouteMatches = router.matchRoutes(router.latestLocation, {
109109
_buildLocation: false,
110110
})
111111

112-
return options.from ??
112+
return (
113+
options.from ??
113114
currentRouteMatches.slice(-1)[0]?.fullPath ??
114115
router.state.matches[matchIndex]!.fullPath
116+
)
115117
}, [router, options.from, matchIndex])
116118

117119
const next = React.useMemo(
@@ -192,10 +194,12 @@ export function useLinkProps<
192194

193195
const doPreload = React.useCallback(
194196
() => {
195-
router.preloadRoute({ ...options, from: getFrom() } as any).catch((err) => {
196-
console.warn(err)
197-
console.warn(preloadWarning)
198-
})
197+
router
198+
.preloadRoute({ ...options, from: getFrom() } as any)
199+
.catch((err) => {
200+
console.warn(err)
201+
console.warn(preloadWarning)
202+
})
199203
},
200204
// eslint-disable-next-line react-hooks/exhaustive-deps
201205
[

packages/react-router/src/useNavigate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function useNavigate<
2626

2727
return React.useCallback(
2828
(options: NavigateOptions) => {
29-
const currentRouteMatches= router.matchRoutes(router.latestLocation, {
29+
const currentRouteMatches = router.matchRoutes(router.latestLocation, {
3030
_buildLocation: false,
3131
})
3232

packages/react-router/tests/link.test.tsx

Lines changed: 81 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -5074,7 +5074,9 @@ describe.each([{ basepath: '' }, { basepath: '/basepath' }])(
50745074
return (
50755075
<>
50765076
<h1>Param Route</h1>
5077-
<Link from={paramRoute.fullPath} to="./a">Link to ./a</Link>
5077+
<Link from={paramRoute.fullPath} to="./a">
5078+
Link to ./a
5079+
</Link>
50785080
<Link to="c" unsafeRelative="path">
50795081
Link to c
50805082
</Link>
@@ -5094,7 +5096,9 @@ describe.each([{ basepath: '' }, { basepath: '/basepath' }])(
50945096
return (
50955097
<>
50965098
<h1>Param A Route</h1>
5097-
<Link from={paramARoute.fullPath} to="..">Link to .. from /param/foo/a</Link>
5099+
<Link from={paramARoute.fullPath} to="..">
5100+
Link to .. from /param/foo/a
5101+
</Link>
50985102
<Outlet />
50995103
</>
51005104
)
@@ -5420,23 +5424,20 @@ describe('relative links to current route', () => {
54205424
const IndexComponent = () => {
54215425
return (
54225426
<>
5423-
<Link
5424-
data-testid="posts-link"
5425-
to='/post'
5426-
>
5427+
<Link data-testid="posts-link" to="/post">
54275428
Post
54285429
</Link>
54295430
<Link
54305431
data-testid="search-link"
5431-
to='.'
5432-
search={{param1: 'value1'}}
5432+
to="."
5433+
search={{ param1: 'value1' }}
54335434
>
54345435
Search
54355436
</Link>
54365437
<Link
54375438
data-testid="search2-link"
5438-
to='.'
5439-
search={{param1: 'value2'}}
5439+
to="."
5440+
search={{ param1: 'value2' }}
54405441
>
54415442
Search2
54425443
</Link>
@@ -5502,23 +5503,20 @@ describe('relative links to current route', () => {
55025503
const IndexComponent = () => {
55035504
return (
55045505
<>
5505-
<Link
5506-
data-testid="posts-link"
5507-
to='/post'
5508-
>
5506+
<Link data-testid="posts-link" to="/post">
55095507
Post
55105508
</Link>
55115509
<Link
55125510
data-testid="search-link"
5513-
to='.'
5514-
search={{param1: 'value1'}}
5511+
to="."
5512+
search={{ param1: 'value1' }}
55155513
>
55165514
Search
55175515
</Link>
55185516
<Link
55195517
data-testid="search2-link"
5520-
to='/post'
5521-
search={{param1: 'value2'}}
5518+
to="/post"
5519+
search={{ param1: 'value2' }}
55225520
>
55235521
Search2
55245522
</Link>
@@ -5582,10 +5580,7 @@ describe('relative links to current route', () => {
55825580
return (
55835581
<>
55845582
<h1 data-testid="index-heading">Index</h1>
5585-
<Link
5586-
data-testid="posts-link"
5587-
to='/posts'
5588-
>
5583+
<Link data-testid="posts-link" to="/posts">
55895584
Posts
55905585
</Link>
55915586
</>
@@ -5617,14 +5612,14 @@ describe('relative links to current route', () => {
56175612
<h1 data-testid="posts-index-heading">Posts</h1>
56185613
<Link
56195614
data-testid="first-post-link"
5620-
to='$postId'
5615+
to="$postId"
56215616
params={{ postId: 'id1' }}
56225617
>
56235618
To first post
56245619
</Link>
56255620
<Link
56265621
data-testid="second-post-link"
5627-
to='.'
5622+
to="."
56285623
params={{ postId: 'id2' }}
56295624
>
56305625
To second post
@@ -5671,7 +5666,9 @@ describe('relative links to current route', () => {
56715666

56725667
await act(() => fireEvent.click(postsButton))
56735668

5674-
expect(await screen.findByTestId('posts-index-heading')).toBeInTheDocument()
5669+
expect(
5670+
await screen.findByTestId('posts-index-heading'),
5671+
).toBeInTheDocument()
56755672
expect(window.location.pathname).toEqual(`/posts${tail}`)
56765673

56775674
const firstPostButton = await screen.findByTestId('first-post-link')
@@ -5702,24 +5699,17 @@ describe('relative links to from route', () => {
57025699
const IndexComponent = () => {
57035700
return (
57045701
<>
5705-
<Link
5706-
data-testid="posts-link"
5707-
to='/post'
5708-
>
5702+
<Link data-testid="posts-link" to="/post">
57095703
Post
57105704
</Link>
57115705
<Link
57125706
data-testid="search-link"
5713-
to='.'
5714-
search={{param1: 'value1'}}
5707+
to="."
5708+
search={{ param1: 'value1' }}
57155709
>
57165710
Search
57175711
</Link>
5718-
<Link
5719-
data-testid="home-link"
5720-
from='/'
5721-
to='.'
5722-
>
5712+
<Link data-testid="home-link" from="/" to=".">
57235713
Go To Home
57245714
</Link>
57255715
<Outlet />
@@ -5782,10 +5772,7 @@ describe('relative links to from route', () => {
57825772
return (
57835773
<>
57845774
<h1 data-testid="index-heading">Index</h1>
5785-
<Link
5786-
data-testid="posts-link"
5787-
to='/posts'
5788-
>
5775+
<Link data-testid="posts-link" to="/posts">
57895776
Posts
57905777
</Link>
57915778
</>
@@ -5817,23 +5804,19 @@ describe('relative links to from route', () => {
58175804
<h1 data-testid="posts-index-heading">Posts</h1>
58185805
<Link
58195806
data-testid="first-post-link"
5820-
to='$postId'
5807+
to="$postId"
58215808
params={{ postId: '1' }}
58225809
>
58235810
To first post
58245811
</Link>
58255812
<Link
58265813
data-testid="second-post-link"
5827-
to='$postId'
5814+
to="$postId"
58285815
params={{ postId: '2' }}
58295816
>
58305817
To second post
58315818
</Link>
5832-
<Link
5833-
data-testid="to-posts-index-link"
5834-
from='/posts'
5835-
to='.'
5836-
>
5819+
<Link data-testid="to-posts-index-link" from="/posts" to=".">
58375820
To posts list
58385821
</Link>
58395822
<Outlet />
@@ -5845,22 +5828,16 @@ describe('relative links to from route', () => {
58455828
return (
58465829
<>
58475830
<h1 data-testid="post-detail-index-heading">Post Detail</h1>
5848-
<Link
5849-
data-testid="post-info-link"
5850-
to='info'
5851-
>
5831+
<Link data-testid="post-info-link" to="info">
58525832
To post info
58535833
</Link>
5854-
<Link
5855-
data-testid="post-notes-link"
5856-
to='notes'
5857-
>
5834+
<Link data-testid="post-notes-link" to="notes">
58585835
To post notes
58595836
</Link>
58605837
<Link
58615838
data-testid="to-post-detail-index-link"
5862-
from='/posts/$postId'
5863-
to='.'
5839+
from="/posts/$postId"
5840+
to="."
58645841
>
58655842
To index detail options
58665843
</Link>
@@ -5912,7 +5889,11 @@ describe('relative links to from route', () => {
59125889
const router = createRouter({
59135890
routeTree: rootRoute.addChildren([
59145891
indexRoute,
5915-
layoutRoute.addChildren([postsRoute.addChildren([postDetailRoute.addChildren([postInfoRoute, postNotesRoute])])]),
5892+
layoutRoute.addChildren([
5893+
postsRoute.addChildren([
5894+
postDetailRoute.addChildren([postInfoRoute, postNotesRoute]),
5895+
]),
5896+
]),
59165897
]),
59175898
trailingSlash: trailingSlash ? 'always' : 'never',
59185899
})
@@ -5923,14 +5904,18 @@ describe('relative links to from route', () => {
59235904

59245905
fireEvent.click(postsButton)
59255906

5926-
expect(await screen.findByTestId('posts-index-heading')).toBeInTheDocument()
5907+
expect(
5908+
await screen.findByTestId('posts-index-heading'),
5909+
).toBeInTheDocument()
59275910
expect(window.location.pathname).toEqual(`/posts${tail}`)
59285911

59295912
const firstPostButton = await screen.findByTestId('first-post-link')
59305913

59315914
fireEvent.click(firstPostButton)
59325915

5933-
expect(await screen.findByTestId('post-detail-index-heading')).toBeInTheDocument()
5916+
expect(
5917+
await screen.findByTestId('post-detail-index-heading'),
5918+
).toBeInTheDocument()
59345919
expect(window.location.pathname).toEqual(`/posts/1${tail}`)
59355920

59365921
const postInfoButton = await screen.findByTestId('post-info-link')
@@ -5940,28 +5925,36 @@ describe('relative links to from route', () => {
59405925
expect(await screen.findByTestId('post-info-heading')).toBeInTheDocument()
59415926
expect(window.location.pathname).toEqual(`/posts/1/info${tail}`)
59425927

5943-
const toPostDetailIndexButton = await screen.findByTestId('to-post-detail-index-link')
5928+
const toPostDetailIndexButton = await screen.findByTestId(
5929+
'to-post-detail-index-link',
5930+
)
59445931

59455932
fireEvent.click(toPostDetailIndexButton)
59465933

5947-
expect(await screen.findByTestId('post-detail-index-heading')).toBeInTheDocument()
59485934
expect(
5949-
screen.queryByTestId("'post-info-heading"),
5950-
).not.toBeInTheDocument()
5935+
await screen.findByTestId('post-detail-index-heading'),
5936+
).toBeInTheDocument()
5937+
expect(screen.queryByTestId("'post-info-heading")).not.toBeInTheDocument()
59515938
expect(window.location.pathname).toEqual(`/posts/1${tail}`)
59525939

59535940
const postNotesButton = await screen.findByTestId('post-notes-link')
59545941

59555942
fireEvent.click(postNotesButton)
59565943

5957-
expect(await screen.findByTestId('post-notes-heading')).toBeInTheDocument()
5944+
expect(
5945+
await screen.findByTestId('post-notes-heading'),
5946+
).toBeInTheDocument()
59585947
expect(window.location.pathname).toEqual(`/posts/1/notes${tail}`)
59595948

5960-
const toPostsIndexButton = await screen.findByTestId('to-posts-index-link')
5949+
const toPostsIndexButton = await screen.findByTestId(
5950+
'to-posts-index-link',
5951+
)
59615952

59625953
fireEvent.click(toPostsIndexButton)
59635954

5964-
expect(await screen.findByTestId('posts-index-heading')).toBeInTheDocument()
5955+
expect(
5956+
await screen.findByTestId('posts-index-heading'),
5957+
).toBeInTheDocument()
59655958
expect(
59665959
screen.queryByTestId("'post-notes-heading"),
59675960
).not.toBeInTheDocument()
@@ -5974,7 +5967,9 @@ describe('relative links to from route', () => {
59745967

59755968
fireEvent.click(secondPostButton)
59765969

5977-
expect(await screen.findByTestId('post-detail-index-heading')).toBeInTheDocument()
5970+
expect(
5971+
await screen.findByTestId('post-detail-index-heading'),
5972+
).toBeInTheDocument()
59785973
expect(window.location.pathname).toEqual(`/posts/2${tail}`)
59795974
},
59805975
)
@@ -5988,10 +5983,12 @@ describe('when on /posts/$postId and navigating to ../ with default `from` /post
59885983
return (
59895984
<>
59905985
<h1 data-testid="index-heading">Index</h1>
5991-
<Link data-testid="posts-link" to='/posts'>Posts</Link>
5986+
<Link data-testid="posts-link" to="/posts">
5987+
Posts
5988+
</Link>
59925989
<Link
59935990
data-testid="index-to-first-post-link"
5994-
to='/posts/$postId/details'
5991+
to="/posts/$postId/details"
59955992
params={{ postId: 'id1' }}
59965993
>
59975994
To first post
@@ -6022,12 +6019,24 @@ describe('when on /posts/$postId and navigating to ../ with default `from` /post
60226019
const PostsComponent = () => {
60236020
const linkVia = () => {
60246021
if (navigateVia === 'Route') {
6025-
return <Link from={postsRoute.fullPath} to='../' data-testid="link-to-home">To Home</Link>
6022+
return (
6023+
<Link
6024+
from={postsRoute.fullPath}
6025+
to="../"
6026+
data-testid="link-to-home"
6027+
>
6028+
To Home
6029+
</Link>
6030+
)
60266031
}
60276032

60286033
const RouteApiLink = getRouteApi('/_layout/posts').Link
60296034

6030-
return <RouteApiLink to='../' data-testid="link-to-home">To Home</RouteApiLink>
6035+
return (
6036+
<RouteApiLink to="../" data-testid="link-to-home">
6037+
To Home
6038+
</RouteApiLink>
6039+
)
60316040
}
60326041

60336042
return (

0 commit comments

Comments
 (0)