AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

@Clerk/Nextjs OnBeforeSetActive Hangs Forever When InvalidateCacheAction Rejects After Redeploy

The App Router client ClerkProvider installs a window.__internal_onBeforeSetActive hook that never resolves if invalidateCacheAction() rejects, causing setActive, sign-in, reverification, and sign-out to hang indefinitely. This occurs routinely on self-hosted Next.js 15/16 after redeployments because server action IDs change, leading to UnrecognizedActionError.

highConfidence 98%NextjsReact Server ComponentsRoute HandlersAffected V7.4.1Affected V7.9.7

Origin Analysis

The Promise executor inside window.__internal_onBeforeSetActive only calls resolve() in the .then() success path of invalidateCacheAction(); no rejection handler is provided, so any rejection (e.g., UnrecognizedActionError from stale server action IDs) leaves the promise permanently pending. clerk-js awaits this hook in setActive and signOut, blocking completion.
1. Create a Next.js App Router app with @clerk/nextjs and a <UserButton />.\n2. Build and start with NEXT_SERVER_ACTIONS_ENCRYPTION_KEY=$(openssl rand -base64 32).\n3. Open the app and sign in.\n4. Stop the server, rebuild with a different NEXT_SERVER_ACTIONS_ENCRYPTION_KEY, and restart.\n5. Without reloading the tab, sign out from the UserButton or run await window.__internal_onBeforeSetActive() in the console.\n6. Observe the promise never settles and sign-out leaves the session intact.

Fixing Code Block

Edge Case Audit

Resolving unconditionally on rejection may mask genuine cache-invalidation failures unrelated to stale deployments, potentially leaving stale client cache until the next router.refresh(). This is acceptable because __internal_onAfterSetActive triggers router.refresh(), but teams that rely on cache invalidation success for immediate data consistency should monitor for failed invalidateCacheAction calls. Rollback: explicitly reject the promise instead of resolving on error and handle the resulting error in clerk-js if strict cache invalidation semantics are required.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state