-
Notifications
You must be signed in to change notification settings - Fork 419
fix(clerk-js): Add a development warning when missing both custom router options #6578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(clerk-js): Add a development warning when missing both custom router options #6578
Conversation
🦋 Changeset detectedLatest commit: ed68208 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
routerPush and routerReplace are not provided in ClerkOptions, but one is specified74bdb06 to
f146a69
Compare
📝 WalkthroughWalkthroughAdds 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
Out-of-scope changes
📜 Recent review detailsConfiguration used: CodeRabbit UI 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ 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)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
6on 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/routerReplaceis 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.
📒 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
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor 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
Useconst assertionsfor literal types:as const
Usesatisfiesoperator 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 ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor 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
f146a69 to
1318de8
Compare
packages/clerk-js/src/core/clerk.ts
Outdated
| (!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.', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, will update!
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
1318de8 to
241dd98
Compare
241dd98 to
ee38852
Compare
ee38852 to
ed68208
Compare
There was a problem hiding this 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 bundlesEven 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 warningNo 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.
📒 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.jsIncreasing the limit by 0.1KB is reasonable given the added dev-only warning. The rest of the bundle thresholds remain unchanged.
packages/clerk-js/src/core/clerk.ts
Outdated
| (this.#options.routerPush || this.#options.routerReplace) && | ||
| (!this.#options.routerPush || !this.#options.routerReplace) | ||
| ) { | ||
| // Typing this.#options as ClerkOptions to ensure proper type checking |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // 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. |
…ter options Signed-off-by: Kenton Duprey <[email protected]>
ed68208 to
12394c2
Compare
Description
Adds a warning in development mode when both
routerPushandrouterReplaceare not provided inClerkOptions, but one is specified.Fixes USER-3123
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit