Skip to content

fix(clerk-js): Handle missing window.location in React Native navigation#7654

Merged
chriscanin merged 4 commits into
core-2from
chris/mobile-392-evan-bacon-expo-sdk-issues-new
Jan 23, 2026
Merged

fix(clerk-js): Handle missing window.location in React Native navigation#7654
chriscanin merged 4 commits into
core-2from
chris/mobile-392-evan-bacon-expo-sdk-issues-new

Conversation

@chriscanin

Copy link
Copy Markdown
Contributor

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:

  • window exists (so inBrowser() returns true)
  • window.location is undefined
    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 test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@chriscanin
chriscanin requested a review from wobsoriano January 22, 2026 21:48
@changeset-bot

changeset-bot Bot commented Jan 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 21bb835

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@clerk/clerk-js Patch
@clerk/chrome-extension Patch
@clerk/expo Patch

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

@vercel

vercel Bot commented Jan 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Jan 22, 2026 10:25pm

Request Review

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.

@wobsoriano wobsoriano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@chriscanin
chriscanin merged commit 1bff12c into core-2 Jan 23, 2026
7 checks passed
@chriscanin
chriscanin deleted the chris/mobile-392-evan-bacon-expo-sdk-issues-new branch January 23, 2026 18:45
@SarahSoutoul

Copy link
Copy Markdown
Contributor

Thought the core-2 branch was an error @wobsoriano ?

@wobsoriano

Copy link
Copy Markdown
Member

Thought the core-2 branch was an error @wobsoriano ?

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

@SarahSoutoul

Copy link
Copy Markdown
Contributor

Thought the core-2 branch was an error @wobsoriano ?

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.

@SarahSoutoul

Copy link
Copy Markdown
Contributor

Thought the core-2 branch was an error @wobsoriano ?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants