Skip to content
Open
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/evan-bacon-window-location-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/clerk-js": patch
---

fix(clerk-js): Handle missing window.location in React Native navigation
21 changes: 21 additions & 0 deletions packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,27 @@ export class Clerk implements ClerkInterface {
return;
}

// In React Native, window exists but window.location does not.
// If we have a custom router, use it directly. Otherwise, return early.
if (typeof window.location === 'undefined') {
const customNavigate =
options?.replace && this.#options.routerReplace ? this.#options.routerReplace : this.#options.routerPush;

if (customNavigate) {
debugLogger.info(`Clerk is navigating to: ${to}`);
return await customNavigate(to, { windowNavigate });
}

// No window.location and no custom router - can't navigate
if (__DEV__) {
console.warn(
'Clerk: Navigation was attempted but window.location is not available and no custom router (routerPush/routerReplace) was provided. ' +
'If you are using React Native, please provide routerPush and routerReplace options to ClerkProvider.',
);
}
return;
}

/**
* Trigger all navigation listeners. In order for modal UI components to close.
*/
Expand Down