Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c89eda9
Added test to prove rerender test for hooks is not possible with tans…
mta-trackunit Jun 24, 2024
c6fb737
prettier
mta-trackunit Jun 25, 2024
4bb62c8
Changed implementation to prove it will work
mta-trackunit Jun 25, 2024
7f2fbc6
Merge branch 'main' into fix-rerender-issue
SeanCassiere Jun 25, 2024
0e8f975
Navigating from kitchensink app dashboard/invoices to dashboard/users…
mta-trackunit Jun 26, 2024
1e24238
Merge remote-tracking branch 'upstream/main' into fix-rerender-issue
mta-trackunit Jul 3, 2024
123d89a
revert and fix navigate by adding a "to" directly in the useEffect si…
mta-trackunit Jul 3, 2024
6aba644
Merge remote-tracking branch 'upstream/main' into fix-rerender-issue
mta-trackunit Jul 4, 2024
a8726a4
cleanup
mta-trackunit Jul 4, 2024
238dc29
ensure lock file was not changed
mta-trackunit Jul 4, 2024
9c88923
now using lock from main
mta-trackunit Jul 4, 2024
7507009
revert change
mta-trackunit Jul 4, 2024
f463d12
revert fix for search
mta-trackunit Jul 5, 2024
d16cf5f
Merge branch 'main' into fix-rerender-issue
mta-trackunit Jul 5, 2024
daf3d27
fixed formatting
mta-trackunit Jul 5, 2024
26d6f6d
Merge branch 'main' into fix-rerender-issue
SeanCassiere Jul 17, 2024
3fce872
Merge branch 'main' into fix-rerender-issue
SeanCassiere Jul 19, 2024
9262e75
Merge branch 'main' into fix-rerender-issue
SeanCassiere Jul 26, 2024
c703848
ci: apply automated fixes
autofix-ci[bot] Jul 26, 2024
05a9a22
chore: do not use memoryHistory
SeanCassiere Jul 26, 2024
b1557a9
Merge remote-tracking branch 'upstream/main' into fix-rerender-issue
mta-trackunit Aug 6, 2024
8164183
Merge branch 'main' into fix-rerender-issue
SeanCassiere Aug 7, 2024
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
8 changes: 2 additions & 6 deletions packages/react-router/src/Matches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,11 @@ export function Matches() {
<router.options.defaultPendingComponent />
) : null

const ResolvedSuspense = !router.state.matches.length
? React.Suspense
: SafeFragment

const inner = (
<ResolvedSuspense fallback={pendingElement}>
<React.Suspense fallback={pendingElement}>
<Transitioner />
<MatchesInner />
</ResolvedSuspense>
</React.Suspense>
)

return router.options.InnerWrap ? (
Expand Down
6 changes: 3 additions & 3 deletions packages/react-router/src/useNavigate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ export function useNavigate<
>(_defaultOpts?: {
from?: FromPathOption<TRouter, TDefaultFrom>
}): UseNavigateResult<TDefaultFrom> {
const router = useRouter()
const { navigate } = useRouter()

return React.useCallback(
(options: NavigateOptions) => {
return router.navigate({
return navigate({
...options,
})
},
[router],
[navigate],
) as UseNavigateResult<TDefaultFrom>
}

Expand Down
68 changes: 68 additions & 0 deletions packages/react-router/tests/link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
configure,
fireEvent,
render,
renderHook,
screen,
waitFor,
} from '@testing-library/react'
Expand All @@ -24,6 +25,7 @@ import {
useMatchRoute,
useParams,
useRouteContext,
useRouterState,
useSearch,
} from '../src'
import { getIntersectionObserverMock } from './utils'
Expand All @@ -46,6 +48,72 @@ afterEach(() => {
})

describe('Link', () => {
test('when using renderHook it returns a hook with same content to prove rerender works', async () => {
Comment thread
SeanCassiere marked this conversation as resolved.
/**
* This is the hook that will be testet.
*
* @returns custom state
*/
const useLocationFromState = () => {
const { location } = useRouterState()

// could return anything just to prove it will work.
const memoLocation = React.useMemo(() => {
return {
href: location.href,
pathname: location.pathname,
}
}, [location.href, location.pathname])

return memoLocation
}

const IndexComponent = ({ children }: { children: React.ReactNode }) => {
return <h1 data-testid="testId">{children}</h1>
}
const RouterContainer = ({ children }: { children: React.ReactNode }) => {
const childrenRef = React.useRef(children)
const memoedRouteTree = React.useMemo(() => {
const rootRoute = createRootRoute()
const indexRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/',
component: () => (
<IndexComponent>{childrenRef.current}</IndexComponent>
),
})
return rootRoute.addChildren([indexRoute])
}, [])

const memoedRouter = React.useMemo(() => {
const router = createRouter({
routeTree: memoedRouteTree,
})

return router
}, [memoedRouteTree])
return <RouterProvider router={memoedRouter} />
}

const { result, rerender } = renderHook(
() => {
return useLocationFromState()
},
{ wrapper: RouterContainer },
)
await waitFor(() => expect(screen.getByTestId('testId')).toBeVisible())
expect(result.current).toBeTruthy()

const original = result.current

rerender()

await waitFor(() => expect(screen.getByTestId('testId')).toBeVisible())
const updated = result.current

expect(original).toBe(updated)
})

test('when a Link is disabled', async () => {
const rootRoute = createRootRoute()
const indexRoute = createRoute({
Expand Down