Skip to content

Commit 2c9a84e

Browse files
committed
fixup! fix(clerk-js): Prevent session cookie removal during offline token refresh
1 parent 4c86bb9 commit 2c9a84e

3 files changed

Lines changed: 9 additions & 10 deletions

File tree

packages/clerk-js/bundlewatch.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"files": [
3-
{ "path": "./dist/clerk.js", "maxSize": "539KB" },
3+
{ "path": "./dist/clerk.js", "maxSize": "540KB" },
44
{ "path": "./dist/clerk.browser.js", "maxSize": "66KB" },
55
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "108KB" },
66
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "307KB" },

packages/shared/src/__tests__/browser.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,15 @@ describe('isValidBrowserOnline', () => {
162162
expect(isValidBrowserOnline()).toBe(false);
163163
});
164164

165-
it('returns FALSE if connection is NOT online, navigator is online, has disabled the webdriver flag, and is not a bot', () => {
165+
it('returns TRUE if connection reports zero values but navigator is online (headless browser)', () => {
166166
userAgentGetter.mockReturnValue(
167167
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/109.0',
168168
);
169169
webdriverGetter.mockReturnValue(false);
170170
onLineGetter.mockReturnValue(true);
171171
connectionGetter.mockReturnValue({ downlink: 0, rtt: 0 });
172172

173-
expect(isValidBrowserOnline()).toBe(false);
173+
expect(isValidBrowserOnline()).toBe(true);
174174
});
175175

176176
it('returns FALSE if connection is online, navigator is NOT online, has disabled the webdriver flag, and is not a bot', () => {

packages/shared/src/browser.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,12 @@ export function isBrowserOnline(): boolean {
7373
return false;
7474
}
7575

76-
const isNavigatorOnline = navigator?.onLine;
77-
78-
// Being extra safe with the experimental `connection` property, as it is not defined in all browsers
79-
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/connection#browser_compatibility
80-
// @ts-ignore
81-
const isExperimentalConnectionOnline = navigator?.connection?.rtt !== 0 && navigator?.connection?.downlink !== 0;
82-
return isExperimentalConnectionOnline && isNavigatorOnline;
76+
// navigator.onLine is the standard API and is reliable for detecting
77+
// complete disconnection (airplane mode, WiFi off, etc.).
78+
// The experimental navigator.connection API (rtt/downlink) was previously
79+
// used as a secondary signal, but it reports zero values in headless browsers
80+
// and CI environments even when connected, causing false offline detection.
81+
return !!navigator.onLine;
8382
}
8483

8584
/**

0 commit comments

Comments
 (0)