Skip to content

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

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

fix(shared): avoid false offline detection in React Native#8084
eliotgevers wants to merge 4 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 status detection for React Native and environments where standard status indicators are unavailable, reducing false "offline" reports.
  • Tests

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

@changeset-bot
Copy link

changeset-bot bot commented Mar 15, 2026

🦋 Changeset detected

Latest commit: b9d7682

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: 9fe7cc70-c562-475e-8c8b-afc3712ef48f

📥 Commits

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

📒 Files selected for processing (1)
  • .changeset/fix_rn_offline_detection.md

📝 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 clearly and concisely describes the main change: fixing false offline detection in React Native by improving the isBrowserOnline() function logic.
Linked Issues check ✅ Passed The PR directly addresses issue #8083 by modifying isBrowserOnline() to return true for React Native and when navigator.onLine is not a boolean, preventing incorrect offline detection.
Out of Scope Changes check ✅ Passed All changes are scoped to the stated objective: isBrowserOnline() modification in browser.ts, a corresponding test in browser.spec.ts, and a changeset entry documenting the fix.
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

You can customize the high-level summary generated by CodeRabbit.

Configure the reviews.high_level_summary_instructions setting to provide custom instructions for generating the high-level summary.

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

2 participants