Skip to content

fix(shared): avoid false offline detection in React Native#8084

Open
eliotgevers wants to merge 6 commits intoclerk:mainfrom
eliotgevers:codex/expo-skipcache-offline-fix
Open

fix(shared): avoid false offline detection in React Native#8084
eliotgevers wants to merge 6 commits intoclerk:mainfrom
eliotgevers:codex/expo-skipcache-offline-fix

Conversation

@eliotgevers
Copy link

@eliotgevers eliotgevers commented Mar 15, 2026

Summary

This fixes false offline detection in React Native / Expo when navigator.onLine is not implemented.

session.getToken({ skipCache: true }) goes through the forced-refresh path, which checks the shared online helper before fetching a fresh token. In React Native, window and navigator exist, but navigator.onLine does not, so the current logic treats the runtime as offline and throws ClerkOfflineError.

This change treats React Native, and runtimes without a boolean navigator.onLine, as online/unknown rather than offline. Actual network failures still surface through the normal fetch path.

Changes

  • return true from isBrowserOnline() for React Native
  • return true when navigator.onLine is not implemented as a boolean
  • add a focused regression test in @clerk/shared

Validation

  • pnpm --filter @clerk/shared test -- src/__tests__/browser.spec.ts
  • manually patched the equivalent native bundle in an Expo repro app and verified that cached token fetch still succeeds and fresh token fetch succeeds after the fix

Fixes #8083

Summary by CodeRabbit

  • Bug Fixes

    • Improved online/offline detection for React Native and other environments lacking standard status indicators to reduce false "offline" reports.
  • Tests

    • Added test coverage for online status detection in React Native-like scenarios to prevent regressions.

@changeset-bot
Copy link

changeset-bot bot commented Mar 15, 2026

🦋 Changeset detected

Latest commit: 3adcdb1

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

This PR includes changesets to release 21 packages
Name Type
@clerk/shared Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/chrome-extension Patch
@clerk/clerk-js Patch
@clerk/expo-passkeys Patch
@clerk/expo Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/hono Patch
@clerk/localizations Patch
@clerk/msw Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/react Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/ui Patch
@clerk/vue 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
Copy link

vercel bot commented Mar 15, 2026

@eliotgevers is attempting to deploy a commit to the Clerk Production Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: e422bfb8-f020-4928-a7a5-e4c9a982f6a1

📥 Commits

Reviewing files that changed from the base of the PR and between ee4c13f and 50ab3b9.

📒 Files selected for processing (1)
  • packages/shared/src/browser.ts

📝 Walkthrough

Walkthrough

isBrowserOnline was updated to return true when navigator.product === 'ReactNative' and to treat non-boolean navigator.onLine values as online (return true); otherwise it returns the boolean navigator.onLine. A unit test was added covering the React Native case where navigator.onLine and related properties are absent. A changeset file was added documenting a patch release for the package.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing false offline detection in React Native by validating navigator.onLine before considering the environment offline.
Linked Issues check ✅ Passed The PR changes directly address the linked issue #8083 by implementing guard logic in isBrowserOnline() to return true when navigator.onLine is not a boolean, and adding regression tests.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing offline detection in React Native: isBrowserOnline() guard, test case, and changeset documentation. No unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use Trivy to scan for security misconfigurations and secrets in Infrastructure as Code files.

Add a .trivyignore file to your project to customize which findings Trivy reports.

Copy link
Member

@chriscanin chriscanin left a comment

Choose a reason for hiding this comment

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

Tested and looking good. Setting this to approved.

@chriscanin chriscanin requested a review from brkalow March 17, 2026 17:13
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.

@clerk/expo: getToken({ skipCache: true }) fails on Expo while cached token fetch succeeds

3 participants