You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 816cd12
Browse filesBrowse the repository at this point in the historyBrowse files
fix(nextjs,clerk-js): Make useAwaitableNavigate handle navigations between pages reliably
We need to use window to store the reference to the buffer, as ClerkProvider might be unmounted and remounted during navigations. If we use a ref, it will be reset when ClerkProvider is unmounted
* We need to invalidate the cache in case the user is navigating to a page that
36
+
* was previously cached using the auth state that was active at the time.
37
+
*
38
+
* We also need to await for the invalidation to happen before we navigate,
39
+
* otherwise the navigation will use the cached page.
40
+
*
41
+
* For example, if we did not invalidate the flow, the following scenario would be broken:
42
+
* - The middleware is configured in such a way that it redirects you back to the same page if a certain condition is true (eg, you need to pick an org)
43
+
* - The user has a <Link href=/> component in the page
44
+
* - The UB is mounted with afterSignOutUrl=/
45
+
* - The user clicks the Link. A nav to / happens, a 307 to the current page is returned so a navigation does not take place. The / navigation is now cached as a 307 to the current page
46
+
* - The user clicks sign out
47
+
* - We call router.refresh()
48
+
* - We navigate to / but its cached and instead, we 'redirect' to the current page
49
+
*
50
+
* For more information on cache invalidation, see:
* Creates an "awaitable" navigation function that will do its best effort to wait for Next.js to finish its route transition.
10
-
*
11
17
* 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
12
18
* `isPending` to flush the stored promises and ensure the navigates "resolve".
// Handle flushing the promise buffer when pending is false. If pending is false and there are promises in the buffer we should be able to safely flush them.
0 commit comments