FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(clerk-js): Handle missing window.location in React Native navigation by chriscanin · Pull Request #7654 · clerk/javascript · GitHub

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

Filter by extension

Filter by extension .md  (1) .ts  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 5 additions & 0 deletions .changeset/evan-bacon-window-location-fix.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL