Skip to content

[WIP] Fix crash in navigation for Clerk's Client Trust feature#7853

Closed
Copilot wants to merge 1 commit intorelease/core-2from
copilot/fix-navbar-navigation-crash
Closed

[WIP] Fix crash in navigation for Clerk's Client Trust feature#7853
Copilot wants to merge 1 commit intorelease/core-2from
copilot/fix-navbar-navigation-crash

Conversation

Copy link
Contributor

Copilot AI commented Feb 16, 2026

Cherry-pick changes from PR #7654: Fix React Native navigation crash

This PR addresses a crash that occurs in React Native when signing in with a password on a new/unrecognized device.

Issue

  • In React Native, window exists but window.location is undefined
  • When Clerk tries to navigate using new URL(to, window.location.href), it crashes with "Cannot read property 'href' of undefined"

Solution

  • Add a check before accessing window.location.href
  • If window.location is undefined, use the custom router (routerPush/routerReplace) if provided
  • If no custom router is provided, log a warning and return gracefully instead of crashing

Checklist

  • Understand the issue from PR fix(clerk-js): Handle missing window.location in React Native navigation #7654
  • Explore the repository structure
  • Locate the navigate() function in packages/clerk-js/src/core/clerk.ts
  • Review existing tests
  • Create a changeset file
  • Apply the fix to the navigate() function
  • Add tests for the React Native scenario
  • Run tests to verify the fix
  • Run code review
  • Run security scan with CodeQL
Original prompt

Cherry-pick the changes from PR #7654 which addresses the following issue:

When signing in with a 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"

The fix checks: if window.location is undefined, the navigation will use the custom router provided. If no custom router is provided either, it will log a warning and handle gracefully instead of crashing.

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@changeset-bot
Copy link

changeset-bot bot commented Feb 16, 2026

⚠️ No Changeset found

Latest commit: ed295a8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Feb 16, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
clerk-js-sandbox Skipped Skipped Feb 16, 2026 6:06pm

Request Review

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants