Skip to content

Commit 0c9b67a

Browse files
committed
apply code rabbit suggestions
1 parent e0b8814 commit 0c9b67a

File tree

8 files changed

+28
-21
lines changed

8 files changed

+28
-21
lines changed

packages/react-router/src/link.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export function useLinkProps<
131131
options.state,
132132
options.mask,
133133
options.unsafeRelative,
134+
getFrom,
134135
],
135136
)
136137

@@ -220,6 +221,7 @@ export function useLinkProps<
220221
options.replace,
221222
options.resetScroll,
222223
options.viewTransition,
224+
getFrom
223225
],
224226
)
225227

packages/react-router/src/useNavigate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function useNavigate<
4242
})
4343
},
4444
// eslint-disable-next-line react-hooks/exhaustive-deps
45-
[_defaultOpts?.from, router.navigate, router.latestLocation],
45+
[_defaultOpts?.from, router.navigate, router.latestLocation, matchIndex],
4646
) as UseNavigateResult<TDefaultFrom>
4747
}
4848

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5682,7 +5682,7 @@ describe('relative links to current route', () => {
56825682

56835683
await act(() => fireEvent.click(secondPostButton))
56845684

5685-
// expect(await screen.findByTestId('post-id2')).toBeInTheDocument()
5685+
expect(await screen.findByTestId('post-id2')).toBeInTheDocument()
56865686
expect(window.location.pathname).toEqual(`/posts/id2${tail}`)
56875687
},
56885688
)
@@ -5934,7 +5934,7 @@ describe('relative links to from route', () => {
59345934
expect(
59355935
await screen.findByTestId('post-detail-index-heading'),
59365936
).toBeInTheDocument()
5937-
expect(screen.queryByTestId("'post-info-heading")).not.toBeInTheDocument()
5937+
expect(screen.queryByTestId('post-info-heading')).not.toBeInTheDocument()
59385938
expect(window.location.pathname).toEqual(`/posts/1${tail}`)
59395939

59405940
const postNotesButton = await screen.findByTestId('post-notes-link')
@@ -5956,10 +5956,10 @@ describe('relative links to from route', () => {
59565956
await screen.findByTestId('posts-index-heading'),
59575957
).toBeInTheDocument()
59585958
expect(
5959-
screen.queryByTestId("'post-notes-heading"),
5959+
screen.queryByTestId('post-notes-heading'),
59605960
).not.toBeInTheDocument()
59615961
expect(
5962-
screen.queryByTestId("'post-detail-index-heading"),
5962+
screen.queryByTestId('post-detail-index-heading'),
59635963
).not.toBeInTheDocument()
59645964
expect(window.location.pathname).toEqual(`/posts${tail}`)
59655965

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,7 @@ describe('relative navigate to current route', () => {
16231623
})
16241624

16251625
const PostsComponent = () => {
1626-
const navigate = postsRoute.useNavigate()
1626+
const navigate = useNavigate()
16271627
return (
16281628
<>
16291629
<h1 data-testid="posts-index-heading">Posts</h1>
@@ -2092,7 +2092,7 @@ describe('relative navigate to from route', () => {
20922092
expect(
20932093
await screen.findByTestId('post-detail-index-heading'),
20942094
).toBeInTheDocument()
2095-
expect(screen.queryByTestId("'post-info-heading")).not.toBeInTheDocument()
2095+
expect(screen.queryByTestId('post-info-heading')).not.toBeInTheDocument()
20962096
expect(window.location.pathname).toEqual(`/posts/1${tail}`)
20972097

20982098
const postNotesButton = await screen.findByTestId('post-notes-btn')
@@ -2112,10 +2112,10 @@ describe('relative navigate to from route', () => {
21122112
await screen.findByTestId('posts-index-heading'),
21132113
).toBeInTheDocument()
21142114
expect(
2115-
screen.queryByTestId("'post-notes-heading"),
2115+
screen.queryByTestId('post-notes-heading'),
21162116
).not.toBeInTheDocument()
21172117
expect(
2118-
screen.queryByTestId("'post-detail-index-heading"),
2118+
screen.queryByTestId('post-detail-index-heading'),
21192119
).not.toBeInTheDocument()
21202120
expect(window.location.pathname).toEqual(`/posts${tail}`)
21212121

packages/router-core/src/router.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,10 @@ export class RouterCore<
14151415
_buildLocation: true,
14161416
})
14171417

1418+
// Now let's find the starting pathname
1419+
// This should default to the current location if no from is provided
1420+
const lastMatch = last(allCurrentLocationMatches)!
1421+
14181422
// check that from path exists in the current route tree
14191423
// do this check only on navigations during test or development
14201424
if (
@@ -1432,7 +1436,7 @@ export class RouterCore<
14321436
})
14331437

14341438
const matchedCurrent = findLast(allFromMatches, (d) => {
1435-
return comparePaths(d.fullPath, currentLocation.pathname)
1439+
return comparePaths(d.fullPath, lastMatch.fullPath)
14361440
})
14371441

14381442
// for from to be invalid it shouldn't just be unmatched to currentLocation
@@ -1442,10 +1446,6 @@ export class RouterCore<
14421446
}
14431447
}
14441448

1445-
// Now let's find the starting pathname
1446-
// This should default to the current location if no from is provided
1447-
const lastMatch = last(allCurrentLocationMatches)!
1448-
14491449
const defaultedFromPath =
14501450
dest.unsafeRelative === 'path'
14511451
? currentLocation.pathname

packages/solid-router/src/link.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ export function useLinkProps<
145145
select: (match) => match.index,
146146
})
147147

148+
const activeLocation = useRouterState({ select: (s) => s.location })
149+
148150
const _options = () => {
149-
const currentRouteMatches = router.matchRoutes(router.latestLocation, {
151+
const currentRouteMatches = router.matchRoutes(activeLocation(), {
150152
_buildLocation: false,
151153
})
152154

@@ -163,6 +165,8 @@ export function useLinkProps<
163165

164166
const next = Solid.createMemo(() => {
165167
currentSearch()
168+
// Access activeLocation to make this memo re-run on route changes
169+
activeLocation()
166170
return router.buildLocation(_options() as any)
167171
})
168172

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5137,7 +5137,7 @@ describe('relative links to from route', () => {
51375137
screen.queryByTestId('post-detail-index-heading'),
51385138
).toBeInTheDocument()
51395139
expect(
5140-
screen.queryByTestId("'post-info-heading"),
5140+
screen.queryByTestId('post-info-heading'),
51415141
).not.toBeInTheDocument()
51425142
expect(window.location.pathname).toEqual(`/posts/1${tail}`)
51435143
})
@@ -5160,10 +5160,10 @@ describe('relative links to from route', () => {
51605160
await waitFor(() => {
51615161
expect(screen.queryByTestId('posts-index-heading')).toBeInTheDocument()
51625162
expect(
5163-
screen.queryByTestId("'post-notes-heading"),
5163+
screen.queryByTestId('post-notes-heading'),
51645164
).not.toBeInTheDocument()
51655165
expect(
5166-
screen.queryByTestId("'post-detail-index-heading"),
5166+
screen.queryByTestId('post-detail-index-heading'),
51675167
).not.toBeInTheDocument()
51685168
expect(window.location.pathname).toEqual(`/posts${tail}`)
51695169
})

packages/solid-router/tests/useNavigate.test.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ beforeEach(() => {
3232
})
3333

3434
afterEach(() => {
35+
history.destroy()
3536
window.history.replaceState(null, 'root', '/')
3637
cleanup()
3738
})
@@ -2072,7 +2073,7 @@ describe('relative navigate to from route', () => {
20722073
screen.queryByTestId('post-detail-index-heading'),
20732074
).toBeInTheDocument()
20742075
expect(
2075-
screen.queryByTestId("'post-info-heading"),
2076+
screen.queryByTestId('post-info-heading'),
20762077
).not.toBeInTheDocument()
20772078
expect(window.location.pathname).toEqual(`/posts/1${tail}`)
20782079
})
@@ -2093,10 +2094,10 @@ describe('relative navigate to from route', () => {
20932094
await waitFor(() => {
20942095
expect(screen.queryByTestId('posts-index-heading')).toBeInTheDocument()
20952096
expect(
2096-
screen.queryByTestId("'post-notes-heading"),
2097+
screen.queryByTestId('post-notes-heading'),
20972098
).not.toBeInTheDocument()
20982099
expect(
2099-
screen.queryByTestId("'post-detail-index-heading"),
2100+
screen.queryByTestId('post-detail-index-heading'),
21002101
).not.toBeInTheDocument()
21012102
expect(window.location.pathname).toEqual(`/posts${tail}`)
21022103
})

0 commit comments

Comments
 (0)