Skip to content

Conversation

@kduprey
Copy link
Member

@kduprey kduprey commented Aug 20, 2025

Description

Adds a warning in development mode when both routerPush and routerReplace are not provided in ClerkOptions, but one is specified.

Fixes USER-3123

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

  • Documentation
    • Clarified a development-mode warning that appears when only one of the router navigation callbacks is supplied, explaining both callbacks are required for custom navigation to work reliably.
  • Chores
    • Added a one-time development-only warning to surface navigation misconfiguration during local testing; no production behavior changes.
    • Minor build/config size metadata adjusted.

@changeset-bot
Copy link

changeset-bot bot commented Aug 20, 2025

🦋 Changeset detected

Latest commit: ed68208

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

This PR includes changesets to release 3 packages
Name Type
@clerk/clerk-js 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

@kduprey kduprey self-assigned this Aug 20, 2025
@vercel
Copy link

vercel bot commented Aug 20, 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 20, 2025 6:09pm

@kduprey kduprey changed the title fix(clerk-js): Add a warning in development mode when both routerPush and routerReplace are not provided in ClerkOptions, but one is specified fix(clerk-js): Add a development warning when missing both custom router options Aug 20, 2025
@kduprey kduprey force-pushed the kenton/user-3123-warn-when-missing-one-of-routerpush-or-routerreplace branch from 74bdb06 to f146a69 Compare August 20, 2025 02:32
@kduprey kduprey marked this pull request as ready for review August 20, 2025 15:29
@kduprey kduprey requested a review from brkalow August 20, 2025 15:30
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 20, 2025

📝 Walkthrough

Walkthrough

Adds a development-only runtime check in packages/clerk-js/src/core/clerk.ts inside Clerk.load that emits a one-time logger.warnOnce when exactly one of routerPush or routerReplace is provided in ClerkOptions. Adds a .changeset/true-mirrors-check.md entry documenting the new warning and updates packages/clerk-js/bundlewatch.config.json maxSize for ./dist/clerk.js. No API signatures, exports, or control flow/return values were changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Warn in development when options omit one of routerPush or routerReplace (USER-3123)

Out-of-scope changes

Code Change Explanation
Added changeset entry (.changeset/true-mirrors-check.md) Documentation-only change not required to satisfy the runtime warning objective.
bundlewatch maxSize increment for ./dist/clerk.js (packages/clerk-js/bundlewatch.config.json) Build-size config tweak unrelated to the runtime warning requirement.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled
  • 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 ed68208 and 12394c2.

📒 Files selected for processing (3)
  • .changeset/true-mirrors-check.md (1 hunks)
  • packages/clerk-js/bundlewatch.config.json (1 hunks)
  • packages/clerk-js/src/core/clerk.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/true-mirrors-check.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/clerk-js/bundlewatch.config.json
  • packages/clerk-js/src/core/clerk.ts
⏰ 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). (4)
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan

🪧 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 @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai 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:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai 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 @coderabbitai help to get the list of available commands.

Other keywords and placeholders

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

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

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/true-mirrors-check.md (1)

6-6: Remove the stray character breaking the changeset file.

There's a lone 6 on Line 6 which will invalidate the changeset markdown/front-matter parsing.

Apply this diff:

@@
 Add a warning in development mode when both `routerPush` and `routerReplace` are not provided in `ClerkOptions`, but one is specified.
-6
🧹 Nitpick comments (1)
packages/clerk-js/src/core/clerk.ts (1)

431-441: Dev-only check is correct; refine detection and message to aid recovery.

The guard correctly fires only when exactly one of routerPush/routerReplace is set in development. Two small improvements:

  • Type-safe presence check: verify they’re functions to avoid truthy non-functions slipping through at runtime.
  • Make the warning action-oriented and indicate which option is missing.

Apply this diff:

-    // In development mode, if custom router options are provided, warn if both routerPush and routerReplace are not provided
-    if (
-      this.#instanceType === 'development' &&
-      (this.#options.routerPush || this.#options.routerReplace) &&
-      (!this.#options.routerPush || !this.#options.routerReplace)
-    ) {
-      logger.warnOnce(
-        'Clerk: Both `routerPush` and `routerReplace` are not defined. This may cause issues with navigation in your application.',
-      );
-    }
+    // In development mode, if custom router options are provided, warn when only one of routerPush/routerReplace is present
+    const hasPush = typeof this.#options.routerPush === 'function';
+    const hasReplace = typeof this.#options.routerReplace === 'function';
+    if (this.#instanceType === 'development' && (hasPush || hasReplace) && !(hasPush && hasReplace)) {
+      const missing = [!hasPush ? 'routerPush' : null, !hasReplace ? 'routerReplace' : null]
+        .filter(Boolean)
+        .join(' & ');
+      logger.warnOnce(
+        `Clerk: Custom router configuration is incomplete. Provide both "routerPush" and "routerReplace" in ClerkOptions so Clerk can handle push and replace navigations. Missing: ${missing}.`,
+      );
+    }

Notes:

  • This remains dev-only and one-time.
  • The message now tells developers exactly what to fix, aligning with the “meaningful error messages + recovery suggestions” guideline.

If you want, I can add unit tests to cover: (1) dev-only warning, (2) warns when only push is set, (3) warns when only replace is set, (4) no warning when both/none are set, (5) no warning in production.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled
  • 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 9f0aad2 and f146a69.

📒 Files selected for processing (2)
  • .changeset/true-mirrors-check.md (1 hunks)
  • packages/clerk-js/src/core/clerk.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{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/clerk-js/src/core/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/clerk-js/src/core/clerk.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/clerk.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/clerk-js/src/core/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/clerk-js/src/core/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/clerk-js/src/core/clerk.ts
**/*

⚙️ CodeRabbit Configuration File

If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

Files:

  • packages/clerk-js/src/core/clerk.ts
.changeset/**

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/true-mirrors-check.md

@kduprey kduprey force-pushed the kenton/user-3123-warn-when-missing-one-of-routerpush-or-routerreplace branch from f146a69 to 1318de8 Compare August 20, 2025 15:43
(!this.#options.routerPush || !this.#options.routerReplace)
) {
logger.warnOnce(
'Clerk: Both `routerPush` and `routerReplace` are not defined. This may cause issues with navigation in your application.',
Copy link
Member

Choose a reason for hiding this comment

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

what about:

`Clerk: Both \`routerPush\` and \`routerReplace\` need to be defined, but \`${!this.#options.routerPush ? "routerPush" : "routerReplace"}\` is not defined. This may cause issues with navigation in your application.`

That way we clearly indicate which is missing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you, will update!

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 20, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: 12394c2

@kduprey kduprey force-pushed the kenton/user-3123-warn-when-missing-one-of-routerpush-or-routerreplace branch from 1318de8 to 241dd98 Compare August 20, 2025 15:52
@kduprey kduprey force-pushed the kenton/user-3123-warn-when-missing-one-of-routerpush-or-routerreplace branch from 241dd98 to ee38852 Compare August 20, 2025 16:05
@kduprey kduprey force-pushed the kenton/user-3123-warn-when-missing-one-of-routerpush-or-routerreplace branch from ee38852 to ed68208 Compare August 20, 2025 16:30
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 (2)
packages/clerk-js/bundlewatch.config.json (2)

3-3: Confirm dev-only code is stripped from production bundles

Even though this is a dev-only warning, the production bundle size limit increased. Please verify the warning is behind a compile-time guard so it can be DCE’d by Rollup/Terser.

Example pattern (outside this file):

  • Ensure the call site is wrapped, so production builds can drop it:
if (process.env.NODE_ENV !== 'production') {
  logger.warnOnce(
    'Clerk: Both `routerPush` and `routerReplace` need to be defined, but one is missing.'
  );
}
  • Alternatively, use your existing DEV invariant or env helper if present.

If this is already in place, the tiny bump may be from non-eliminated strings or shared code; otherwise, gating it should avoid needing this threshold increase.


3-3: Add tests to cover the new development warning

No tests were added in this PR. Recommend adding unit tests that:

  • Call Clerk.load with only routerPush or only routerReplace and assert logger.warnOnce is invoked exactly once.
  • Call with both defined and with neither defined and assert no warnings.

I can draft the tests (including mocking the logger and toggling NODE_ENV) if you’d like.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled
  • 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 ee38852 and ed68208.

📒 Files selected for processing (3)
  • .changeset/true-mirrors-check.md (1 hunks)
  • packages/clerk-js/bundlewatch.config.json (1 hunks)
  • packages/clerk-js/src/core/clerk.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .changeset/true-mirrors-check.md
  • packages/clerk-js/src/core/clerk.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{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/clerk-js/bundlewatch.config.json
**/*

⚙️ CodeRabbit Configuration File

If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

Files:

  • packages/clerk-js/bundlewatch.config.json
🔇 Additional comments (1)
packages/clerk-js/bundlewatch.config.json (1)

3-3: LGTM: Small, justified maxSize bump for clerk.js

Increasing the limit by 0.1KB is reasonable given the added dev-only warning. The rest of the bundle thresholds remain unchanged.

@kduprey kduprey requested a review from dstaley August 20, 2025 18:02
(this.#options.routerPush || this.#options.routerReplace) &&
(!this.#options.routerPush || !this.#options.routerReplace)
) {
// Typing this.#options as ClerkOptions to ensure proper type checking
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Typing this.#options as ClerkOptions to ensure proper type checking
// Typing this.#options as ClerkOptions to ensure proper type checking. TypeScript will infer the type as `never`
// since missing both `routerPush` and `routerReplace` is not a valid ClerkOptions.

@kduprey kduprey force-pushed the kenton/user-3123-warn-when-missing-one-of-routerpush-or-routerreplace branch from ed68208 to 12394c2 Compare August 20, 2025 18:07
@kduprey kduprey enabled auto-merge (squash) August 20, 2025 18:08
@kduprey kduprey merged commit 0f96720 into main Aug 20, 2025
39 checks passed
@kduprey kduprey deleted the kenton/user-3123-warn-when-missing-one-of-routerpush-or-routerreplace branch August 20, 2025 18:25
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