-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(elements): Fix elements router usage (#4513)
Co-authored-by: Bryce Kalow <bryce@clerk.dev>
- Loading branch information
1 parent
f5f6c4d
commit f7472e2
Showing
18 changed files
with
119 additions
and
133 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,9 @@ | ||
--- | ||
'@clerk/elements': patch | ||
'@clerk/nextjs': patch | ||
'@clerk/shared': patch | ||
'@clerk/types': patch | ||
'@clerk/clerk-js': patch | ||
--- | ||
|
||
Fixes issues in `ClerkRouter` that were causing inaccurate pathnames within Elements flows. Also fixes a dependency issue where `@clerk/elements` was pulling in the wrong version of `@clerk/shared`. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { Route, Router, useClerkRouter } from '@clerk/shared/router'; | ||
export { Route, Router, useClerkRouter, ClerkHostRouterContext } from '@clerk/shared/router'; | ||
export { useVirtualRouter } from './virtual'; | ||
export { useNextRouter } from './next'; |
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,35 @@ | ||
import type { ClerkHostRouter } from '@clerk/types'; | ||
import { usePathname, useRouter, useSearchParams } from 'next/navigation'; | ||
|
||
import { NEXT_WINDOW_HISTORY_SUPPORT_VERSION } from '~/internals/constants'; | ||
|
||
import { usePathnameWithoutCatchAll } from '../utils/path-inference/next'; | ||
|
||
/** | ||
* Clerk Elements router integration with Next.js's router. | ||
*/ | ||
export const useNextRouter = (): ClerkHostRouter => { | ||
const router = useRouter(); | ||
const pathname = usePathname(); | ||
const searchParams = useSearchParams(); | ||
const inferredBasePath = usePathnameWithoutCatchAll(); | ||
|
||
// The window.history APIs seem to prevent Next.js from triggering a full page re-render, allowing us to | ||
// preserve internal state between steps. | ||
const canUseWindowHistoryAPIs = | ||
typeof window !== 'undefined' && window.next && window.next.version >= NEXT_WINDOW_HISTORY_SUPPORT_VERSION; | ||
|
||
return { | ||
mode: 'path', | ||
name: 'NextRouter', | ||
push: (path: string) => router.push(path), | ||
replace: (path: string) => | ||
canUseWindowHistoryAPIs ? window.history.replaceState(null, '', path) : router.replace(path), | ||
shallowPush(path: string) { | ||
canUseWindowHistoryAPIs ? window.history.pushState(null, '', path) : router.push(path, {}); | ||
}, | ||
pathname: () => pathname, | ||
searchParams: () => searchParams, | ||
inferredBasePath: () => inferredBasePath, | ||
}; | ||
}; |
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
Oops, something went wrong.