Skip to content

fix(nextjs): settle onBeforeSetActive when cache invalidation fails (Core 2) - #10949

Open
phamtanminhtien wants to merge 1 commit into
clerk:release/core-2from
phamtanminhtien:fix/nextjs-settle-before-set-active-core-2
Open

phamtanminhtien wants to merge 1 commit into
clerk:release/core-2from
phamtanminhtien:fix/nextjs-settle-before-set-active-core-2

Conversation

@phamtanminhtien

Copy link
Copy Markdown

Description

Backports #10852 to Core 2 (@clerk/nextjs 6.x).

In App Router apps, window.__unstable__onBeforeSetActive waits for invalidateCacheAction() with .then(() => resolve()) and no rejection handler. When the action rejects, the promise never settles and setActive() hangs forever. The common case is a tab opened before a redeploy: its Server Action ID no longer exists, the server answers 409 UnrecognizedActionError: 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 main does now. __unstable__onAfterSetActive still refreshes the router after the transition. The rest of the hook (the Next.js 13 startTransition path and the sign-out no-op on Next.js 15+) is unchanged on this branch.

Fixes #9987 for Core 2.

How to test

The full @clerk/nextjs suite has 42 failures in src/server/__tests__/clerkMiddleware.test.ts on Node 24 (RequestInit: Expected signal ... to be an instance of AbortSignal). They fail the same way on release/core-2 without this change.

Checklist

  • pnpm test runs as expected.
  • pnpm 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:

…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.
@vercel

vercel Bot commented Nov 23, 2026

Copy link
Copy Markdown

@phamtanminhtien is attempting to deploy a commit to the Clerk Production Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@changeset-bot

changeset-bot Bot commented Nov 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d896c96

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

This PR includes changesets to release 1 package
Name Type
@clerk/nextjs 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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant