Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/shared/src/__tests__/browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,17 @@ describe('isValidBrowserOnline', () => {

expect(isValidBrowserOnline()).toBe(true);
});

it('returns TRUE in React Native when navigator.onLine is not implemented', () => {
userAgentGetter.mockReturnValue(undefined);
webdriverGetter.mockReturnValue(undefined);
onLineGetter.mockReturnValue(undefined);
connectionGetter.mockReturnValue(undefined);
Object.defineProperty(window.navigator, 'product', {
configurable: true,
get: () => 'ReactNative',
});

expect(isValidBrowserOnline()).toBe(true);
});
});
10 changes: 10 additions & 0 deletions packages/shared/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ export function isBrowserOnline(): boolean {
return false;
}

// React Native / Expo defines a Navigator object but does not implement
// the browser-only navigator.onLine API.
if (navigator.product === 'ReactNative') {
return true;
}

if (typeof navigator.onLine !== 'boolean') {
return true;
}

// navigator.onLine is the standard API and is reliable for detecting
// complete disconnection (airplane mode, WiFi off, etc.).
// The experimental navigator.connection API (rtt/downlink) was previously
Expand Down
Loading