-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX [#58788]: Fixed useParams hook undesired re-renders and updated i…
…t to use PathParamsContext in the app router. (#60708) Moved app-dir path params parsing logic from `useParams` to `AppRouter`. This allows for the use of `PathParamsContext` in the `useParams` hook for both pages and app routers. In addition, this allows for memoization of the layout tree which fixes undesired re-renders of the `useParams` hook. Fixes [#58788](#58788) Closes NEXT-2434 --------- Co-authored-by: Zack Tanner <zacktanner@gmail.com>
- Loading branch information
1 parent
c48a0f8
commit 7ba4a0d
Showing
5 changed files
with
106 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
test/e2e/app-dir/use-params/app/rerenders/[dynamic]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use client' | ||
import Link from 'next/link' | ||
import { useParams } from 'next/navigation' | ||
export default function Page() { | ||
const params = useParams() | ||
|
||
return ( | ||
<div> | ||
<Link href="/foo">Link</Link> | ||
<div id="random">{Math.random()}</div> | ||
<div id="params">{JSON.stringify(params?.dynamic)}</div> | ||
</div> | ||
) | ||
} |
10 changes: 10 additions & 0 deletions
10
test/e2e/app-dir/use-params/pages/pages-dir/[dynamic]/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { useParams } from 'next/navigation' | ||
export default function Page() { | ||
const params = useParams() | ||
|
||
return ( | ||
<div> | ||
<div id="params">{JSON.stringify(params?.dynamic)}</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters