fix(clerk-js): Handle missing window.location in React Native navigation#7654
Conversation
🦋 Changeset detectedLatest commit: 21bb835 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.
|
Update the version of @clerk/clerk-js from major to patch and fix handling of missing window.location in React Native navigation.
Fixed crash in React Native when `window.location` is undefined during navigation, improving redirect-based flows.
|
Thought the |
Oof my bad. Would you like to cherry pick this pointing to release/core-2? I can approve and merge. Not on my laptop atm |
Yup will do! Np. |
Done here: #7854 |
Description
The fix that I have added is for the "needs second factor":
When signing in with password on a new/unrecognized device, Clerk's Client Trust feature returns needs_second_factor status. Clerk then tries to navigate to the second factor UI by calling its internal navigate() function.
The problem: navigate() in packages/clerk-js/src/core/clerk.ts does this:
let toURL = new URL(to, window.location.href);
In React Native:
Result: Crash with "Cannot read property 'href' of undefined"
We now check for the window location, and if it cant be found, we will replace the navigation with a router.push / router.replace because in React Native, there's no window.location, the router is the only way to navigate. The fix checks: if window.location is undefined, use the custom router. If no custom router was provided either, warn and bail out gracefully instead of crashing.
MOBILE-392: Evan Bacon - Expo SDK issues
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change