Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/true-mirrors-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Add a development-mode warning when exactly one of `routerPush` or `routerReplace` is provided in `ClerkOptions`. Both must be defined together for custom router navigation to work correctly.
2 changes: 1 addition & 1 deletion packages/clerk-js/bundlewatch.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"files": [
{ "path": "./dist/clerk.js", "maxSize": "626KB" },
{ "path": "./dist/clerk.js", "maxSize": "626.1KB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "78KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "119KB" },
{ "path": "./dist/clerk.headless*.js", "maxSize": "61KB" },
Expand Down
15 changes: 15 additions & 0 deletions packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,21 @@ export class Clerk implements ClerkInterface {

this.#options = this.#initOptions(options);

// 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)
) {
// 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.
const options = this.#options as ClerkOptions;
const missingRouter = !options.routerPush ? 'routerPush' : 'routerReplace';
logger.warnOnce(
`Clerk: Both \`routerPush\` and \`routerReplace\` need to be defined, but \`${missingRouter}\` is not defined. This may cause issues with navigation in your application.`,
);
}

/**
* Listen to `Session.getToken` resolving to emit the updated session
* with the new token to the state listeners.
Expand Down
Loading