Skip to content

Conversation

@nikosdouvlis
Copy link
Member

@nikosdouvlis nikosdouvlis commented Aug 29, 2025

Description

So that adding async just to make TS happy is no longer needed:

await signIn.finalize({
        navigate: async () => {
                    ^ this shouldnt be needed
          router.push("/dashboard");
        },
});

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:

Summary by CodeRabbit

  • Refactor
    • Navigation callback now supports both synchronous and asynchronous execution, letting callers choose whether to await it.
    • Backward compatible: existing integrations continue working; TypeScript consumers can opt to treat the callback as void or Promise-returning as needed.

@changeset-bot
Copy link

changeset-bot bot commented Aug 29, 2025

🦋 Changeset detected

Latest commit: 4708765

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

This PR includes changesets to release 22 packages
Name Type
@clerk/types Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/clerk-js Patch
@clerk/elements Patch
@clerk/expo-passkeys Patch
@clerk/clerk-expo Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/localizations Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/clerk-react Patch
@clerk/remix Patch
@clerk/shared Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/themes Patch
@clerk/vue Patch
@clerk/chrome-extension 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

@vercel
Copy link

vercel bot commented Aug 29, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Aug 29, 2025 0:19am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 29, 2025

Walkthrough

Updated the SetActiveNavigate exported type in packages/types/src/clerk.ts to allow the navigate callback to return either void or a Promise, and added a patch-level changeset reflecting this public API type change.

Changes

Cohort / File(s) Summary
Types: SetActiveNavigate signature
packages/types/src/clerk.ts
Broadened return type for SetActiveNavigate from Promise<unknown> to void | Promise<unknown>.
Changeset: patch note
.changeset/nice-pans-jog.md
Added patch changeset documenting the type-level API change for @clerk/types (signature updated to void | Promise<void>).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I twitch my whiskers at a change so light,
Now callbacks may sleep or spring to flight.
I hop through typings, quick and spry,
Void or Promise—either will fly.
A carrot nod to API delight. 🥕

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch nikos/fix-setactive-finalize-navigate

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 29, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@6662

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@6662

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@6662

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@6662

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@6662

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@6662

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@6662

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@6662

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@6662

@clerk/express

npm i https://pkg.pr.new/@clerk/express@6662

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@6662

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@6662

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@6662

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@6662

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@6662

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@6662

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@6662

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@6662

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@6662

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@6662

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@6662

@clerk/types

npm i https://pkg.pr.new/@clerk/types@6662

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@6662

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@6662

commit: 4708765

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/types/src/clerk.ts (3)

1218-1234: Update docs/example to reflect sync callback.

The example under SetActiveParams.navigate still shows an async arrow; it’s no longer required. Suggest revising to demonstrate a sync callback.

@@
-   * await clerk.setActive({
-   *   session,
-   *   navigate: async ({ session }) => {
+   * await clerk.setActive({
+   *   session,
+   *   // navigate can be sync or async; returning a value is ignored.
+   *   navigate: ({ session }) => {
    *     const currentTask = session.currentTask;
    *     if (currentTask) {
-   *       await router.push(`/onboarding/${currentTask.key}`)
+   *       router.push(`/onboarding/${currentTask.key}`)
    *       return
    *     }
    *
    *     router.push('/dashboard');
    *   }
    * });

123-124: Add JSDoc on the public type to clarify the contract.

Explicitly document that return values are ignored and the function may be sync or async.

 export type BeforeEmitCallback = (session?: SignedInSessionResource | null) => void | Promise<any>;
- export type SetActiveNavigate = ({ session }: { session: SessionResource }) => void | Promise<unknown>;
+ /**
+  * Callback invoked just before committing the new active session/organization.
+  * May be synchronous or asynchronous. Any returned value is ignored.
+  */
+ export type SetActiveNavigate = ({ session }: { session: SessionResource }) => void | Promise<unknown>;

123-123: Optional: consider a shared Awaitable utility and tightening to void.

Define type Awaitable<T = void> = T | Promise<T> and use Awaitable<void> here. It clarifies intent (no meaningful return) and can unify other unions (Promise<unknown> | void) across this file.

Example:

export type Awaitable<T = void> = T | Promise<T>;
export type SetActiveNavigate = ({ session }: { session: SessionResource }) => Awaitable<void>;
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2a82737 and f06856c.

📒 Files selected for processing (1)
  • packages/types/src/clerk.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/types/src/clerk.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/types/src/clerk.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/types/src/clerk.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/types/src/clerk.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/types/src/clerk.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/types/src/clerk.ts
🧬 Code graph analysis (1)
packages/types/src/clerk.ts (1)
packages/types/src/session.ts (1)
  • SessionResource (208-261)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Build Packages
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (2)
packages/types/src/clerk.ts (2)

123-123: Allowing sync navigate callbacks is correct and backward-compatible.

Loosening SetActiveNavigate to void | Promise<unknown> matches existing patterns (e.g., CustomNavigation) and removes the need for gratuitous async. Looks good.


95-98: Restrict fixes to finalize implementations only
Your ripgrep scan surfaced every return navigate(...) across UI and core code, but only async finalize(params?: { navigate?: SetActiveNavigate }) => Promise<void> implementations risk a Promise<unknown> vs Promise<void> mismatch. Locate each checkout‐cache finalize method—i.e. where you receive params.navigate—and replace any

return params.navigate!();

with

await params.navigate!();
return;

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.changeset/nice-pans-jog.md (1)

6-6: Stray character at end of file.

There’s an unexpected 6 on the last line that looks accidental and could be confusing in the release note.

-6
+
🧹 Nitpick comments (1)
.changeset/nice-pans-jog.md (1)

5-5: Clarify the body and include the exact type plus a brief migration note.

Consider stating the precise signature and adding a short rationale/example so release notes are self-contained.

-fix(types): Change return type of SetActiveNavigate to allow void or Promise
+fix(types): allow sync or async navigate callback in SetActiveNavigate
+
+SetActiveNavigate now returns `void | Promise<void>` so callers don't need to mark
+the navigate callback as `async` purely for typing purposes.
+
+Before:
+```ts
+await signIn.finalize({
+  navigate: async () => { router.push('/dashboard'); },
+});
+```
+After:
+```ts
+await signIn.finalize({
+  navigate: () => { router.push('/dashboard'); },
+});
+```
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f06856c and 4708765.

📒 Files selected for processing (1)
  • .changeset/nice-pans-jog.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
.changeset/**

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/nice-pans-jog.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Static analysis
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
.changeset/nice-pans-jog.md (1)

1-3: Frontmatter looks correct for a patch release of @clerk/types.

This will bump @clerk/types with a patch as intended.

Comment on lines +1 to +5
---
"@clerk/types": patch
---

fix(types): Change return type of SetActiveNavigate to allow void or Promise
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify consistency with the actual type change across the repo.

Ensure the exported type is exactly void | Promise<void> (not Promise<unknown>) everywhere it’s declared or re-exported.


🏁 Script executed:

#!/bin/bash
# Verify SetActiveNavigate declaration(s) and references align with the changeset.

# 1) Locate the type definition(s)
rg -nP -C2 --type=ts 'export\s+type\s+SetActiveNavigate\b.*='

# 2) Show the return type in context
rg -nP -C3 --type=ts '(SetActiveNavigate|navigate\s*:\s*\(\{?\s*session)' | sed -n '1,200p'

# 3) Check for Promise<unknown> vs Promise<void> usage nearby
rg -nP --type=ts 'Promise<unknown>|Promise<void>'

# 4) Confirm no other packages declare their own SetActiveNavigate that would also need a changeset
rg -nP --type=ts '\bSetActiveNavigate\b' -g '!node_modules/**'

Length of output: 38291


Change SetActiveNavigate return type to void | Promise

In packages/types/src/clerk.ts line 123, update

export type SetActiveNavigate = ({ session }: { session: SessionResource }) => void | Promise<unknown>;

to

export type SetActiveNavigate = ({ session }: { session: SessionResource }) => void | Promise<void>;

and ensure all imports/uses (e.g. useCheckout.ts, SignInFuture, SignUpFuture, clerk-js checkout) and related tests align with the new Promise<void> signature.

🤖 Prompt for AI Agents
In .changeset/nice-pans-jog.md lines 1-5: update the type in
packages/types/src/clerk.ts (around line 123) from Promise<unknown> to
Promise<void> for SetActiveNavigate so its signature becomes ({ session }: {
session: SessionResource }) => void | Promise<void>; then update all usages and
imports (e.g., useCheckout.ts, SignInFuture, SignUpFuture, clerk-js checkout) to
return either void or Promise<void> (adjust async functions to return/resolve
with no value) and update related tests to expect/await Promise<void> results or
to not assert on returned value.

@nikosdouvlis nikosdouvlis merged commit a50cfc8 into main Sep 1, 2025
39 checks passed
@nikosdouvlis nikosdouvlis deleted the nikos/fix-setactive-finalize-navigate branch September 1, 2025 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants