Skip to content

Commit cda9dd2

Browse files
committed
Apply Chris changes
1 parent d7135bd commit cda9dd2

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

.changeset/sixty-gifts-stand.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
fix(clerk-js): Handle missing window.location in React Native navigation

packages/clerk-js/src/core/clerk.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,27 @@ export class Clerk implements ClerkInterface {
16661666
return;
16671667
}
16681668

1669+
// In React Native, window exists but window.location does not.
1670+
// If we have a custom router, use it directly. Otherwise, return early.
1671+
if (typeof window.location === 'undefined') {
1672+
const customNavigate =
1673+
options?.replace && this.#options.routerReplace ? this.#options.routerReplace : this.#options.routerPush;
1674+
1675+
if (customNavigate) {
1676+
debugLogger.info(`Clerk is navigating to: ${to}`);
1677+
return await customNavigate(to, { windowNavigate });
1678+
}
1679+
1680+
// No window.location and no custom router - can't navigate
1681+
if (__DEV__) {
1682+
console.warn(
1683+
'Clerk: Navigation was attempted but window.location is not available and no custom router (routerPush/routerReplace) was provided. ' +
1684+
'If you are using React Native, please provide routerPush and routerReplace options to ClerkProvider.',
1685+
);
1686+
}
1687+
return;
1688+
}
1689+
16691690
/**
16701691
* Trigger all navigation listeners. In order for modal UI components to close.
16711692
*/

0 commit comments

Comments
 (0)