Skip to content

fix(nextjs,clerk-js): Make useAwaitableNavigate handle navigations be…#2899

Merged
nikosdouvlis merged 1 commit intomainfrom
nikos/v5-fix-awaitable-navigate
Mar 1, 2024
Merged

fix(nextjs,clerk-js): Make useAwaitableNavigate handle navigations be…#2899
nikosdouvlis merged 1 commit intomainfrom
nikos/v5-fix-awaitable-navigate

Conversation

@nikosdouvlis
Copy link
Member

…tween 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

v5 port of #2889

Description

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@changeset-bot
Copy link

changeset-bot bot commented Feb 29, 2024

🦋 Changeset detected

Latest commit: 816cd12

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@clerk/clerk-js Patch
@clerk/nextjs Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@nikosdouvlis
Copy link
Member Author

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @nikosdouvlis - the snapshot version command generated the following package versions:

Package Version
@clerk/backend 1.0.1-snapshot.v009a4cc
@clerk/chrome-extension 1.0.1-snapshot.v009a4cc
@clerk/clerk-js 5.0.1-snapshot.v009a4cc
@clerk/clerk-expo 1.0.1-snapshot.v009a4cc
@clerk/fastify 1.0.1-snapshot.v009a4cc
gatsby-plugin-clerk 5.0.1-snapshot.v009a4cc
@clerk/localizations 2.0.1-snapshot.v009a4cc
@clerk/nextjs 5.0.1-snapshot.v009a4cc
@clerk/clerk-react 5.0.1-snapshot.v009a4cc
@clerk/remix 4.0.1-snapshot.v009a4cc
@clerk/clerk-sdk-node 5.0.1-snapshot.v009a4cc
@clerk/shared 2.0.1-snapshot.v009a4cc
@clerk/themes 2.0.1-snapshot.v009a4cc
@clerk/types 4.0.1-snapshot.v009a4cc

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/backend

npm i @clerk/backend@1.0.1-snapshot.v009a4cc --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@1.0.1-snapshot.v009a4cc --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.0.1-snapshot.v009a4cc --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@1.0.1-snapshot.v009a4cc --save-exact

@clerk/fastify

npm i @clerk/fastify@1.0.1-snapshot.v009a4cc --save-exact

gatsby-plugin-clerk

npm i gatsby-plugin-clerk@5.0.1-snapshot.v009a4cc --save-exact

@clerk/localizations

npm i @clerk/localizations@2.0.1-snapshot.v009a4cc --save-exact

@clerk/nextjs

npm i @clerk/nextjs@5.0.1-snapshot.v009a4cc --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@5.0.1-snapshot.v009a4cc --save-exact

@clerk/remix

npm i @clerk/remix@4.0.1-snapshot.v009a4cc --save-exact

@clerk/clerk-sdk-node

npm i @clerk/clerk-sdk-node@5.0.1-snapshot.v009a4cc --save-exact

@clerk/shared

npm i @clerk/shared@2.0.1-snapshot.v009a4cc --save-exact

@clerk/themes

npm i @clerk/themes@2.0.1-snapshot.v009a4cc --save-exact

@clerk/types

npm i @clerk/types@4.0.1-snapshot.v009a4cc --save-exact

@nikosdouvlis nikosdouvlis force-pushed the nikos/v5-fix-awaitable-navigate branch from 009a4cc to ee06378 Compare February 29, 2024 23:50
…tween 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
@nikosdouvlis nikosdouvlis force-pushed the nikos/v5-fix-awaitable-navigate branch from ee06378 to 816cd12 Compare March 1, 2024 00:35
@nikosdouvlis nikosdouvlis merged commit 0462241 into main Mar 1, 2024
@nikosdouvlis nikosdouvlis deleted the nikos/v5-fix-awaitable-navigate branch March 1, 2024 00:45
jacekradko added a commit that referenced this pull request Mar 5, 2026
…lution

Add unit and integration tests to validate that removing usePathname
from useInternalNavFun's effect deps (#7989) doesn't regress the
navigation promise flushing behavior originally fixed in #2899.

Unit tests:
- Single navigation promise resolves via isPending alone
- Pre-existing window buffer flushed on mount (ClerkProvider remount)
- Pending promises flushed on unmount (ClerkProvider unmount)
- Internal navigations use history pushState instead of router

Integration tests (cache-components / cacheComponents: true):
- Sign out completes without hanging (exercises full setActive → navigate → routerPush → useInternalNavFun chain)
- Protected route redirects correctly after sign out (validates cache invalidation + navigation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants