-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into renovate/npm-next-vulnerability
- Loading branch information
Showing
5 changed files
with
62 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@clerk/nextjs': patch | ||
--- | ||
|
||
Utilize an awaitable replace function internally to avoid race conditions when using `router.replace`. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use client'; | ||
|
||
import { useRouter } from 'next/navigation'; | ||
|
||
import { useInternalNavFun } from './useInternalNavFun'; | ||
|
||
/** | ||
* Creates an "awaitable" navigation function that will do its best effort to wait for Next.js to finish its route transition. | ||
* This is accomplished by wrapping the call to `router.push` in `startTransition()`, which should rely on React to coordinate the pending state. We key off of | ||
* `isPending` to flush the stored promises and ensure the navigates "resolve". | ||
*/ | ||
export const useAwaitablePush = () => { | ||
const router = useRouter(); | ||
|
||
return useInternalNavFun({ | ||
windowNav: window?.history.pushState.bind(window.history), | ||
routerNav: router.push.bind(router), | ||
}); | ||
}; |
19 changes: 19 additions & 0 deletions
19
packages/nextjs/src/app-router/client/useAwaitableReplace.ts
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,19 @@ | ||
'use client'; | ||
|
||
import { useRouter } from 'next/navigation'; | ||
|
||
import { useInternalNavFun } from './useInternalNavFun'; | ||
|
||
/** | ||
* Creates an "awaitable" navigation function that will do its best effort to wait for Next.js to finish its route transition. | ||
* This is accomplished by wrapping the call to `router.replace` in `startTransition()`, which should rely on React to coordinate the pending state. We key off of | ||
* `isPending` to flush the stored promises and ensure the navigates "resolve". | ||
*/ | ||
export const useAwaitableReplace = () => { | ||
const router = useRouter(); | ||
|
||
return useInternalNavFun({ | ||
windowNav: window?.history.replaceState.bind(window.history), | ||
routerNav: router.replace.bind(router), | ||
}); | ||
}; |
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