Repository navigation
fix(nextjs): settle onBeforeSetActive when cache invalidation fails (Core 2) - #10949
phamtanminhtien wants to merge 1 commit into
Conversation
…Core 2) Backport of clerk#10852 to Core 2. When invalidateCacheAction() rejects, for example because the tab still holds a Server Action ID from a previous deployment, the promise returned by __unstable__onBeforeSetActive never resolved and setActive() hung forever.
|
@phamtanminhtien is attempting to deploy a commit to the Clerk Production Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
🦋 Changeset detectedLatest commit: d896c96 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Description
Backports #10852 to Core 2 (
@clerk/nextjs6.x).In App Router apps,
window.__unstable__onBeforeSetActivewaits forinvalidateCacheAction()with.then(() => resolve())and no rejection handler. When the action rejects, the promise never settles andsetActive()hangs forever. The common case is a tab opened before a redeploy: its Server Action ID no longer exists, the server answers 409UnrecognizedActionError: Server Action "…" was not found on the server, and a custom sign-in flow stays on its loading state until the page is reloaded.The fix ignores the rejection and resolves, the same as
maindoes now.__unstable__onAfterSetActivestill refreshes the router after the transition. The rest of the hook (the Next.js 13startTransitionpath and the sign-out no-op on Next.js 15+) is unchanged on this branch.Fixes #9987 for Core 2.
How to test
pnpm --filter @clerk/nextjs test -- src/app-router/clientClerkProvider.test.tsxis adapted from fix(nextjs): settle onBeforeSetActive when cache invalidation fails #10852 to the Core 2 hook names. Without the fix, the two rejection tests fail (one reportshung, the other times out).The full
@clerk/nextjssuite has 42 failures insrc/server/__tests__/clerkMiddleware.test.tson Node 24 (RequestInit: Expected signal ... to be an instance of AbortSignal). They fail the same way onrelease/core-2without this change.Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change