Skip to content

Commit cb7de89

Browse files
authored
fix(clerk-js): Revert offlineScheduler (clerk#5279)
1 parent e05f275 commit cb7de89

File tree

5 files changed

+11
-67
lines changed

5 files changed

+11
-67
lines changed

.changeset/eighty-trains-attend.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clerk/clerk-js": patch
3+
---
4+
5+
Revert offlineScheduler

integration/tests/sign-out-smoke.test.ts

-12
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,6 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('sign out
2222

2323
test('sign out through all open tabs at once', async ({ page, context }) => {
2424
const mainTab = createTestUtils({ app, page, context });
25-
await mainTab.page.addInitScript(() => {
26-
/**
27-
* Playwright may define connection incorrectly, we are overriding to null
28-
*/
29-
if (
30-
navigator.onLine &&
31-
// @ts-expect-error Cannot find `connection`
32-
(navigator?.connection?.rtt === 0 || navigator?.downlink?.rtt === 0)
33-
) {
34-
Object.defineProperty(Object.getPrototypeOf(navigator), 'connection', { value: null });
35-
}
36-
});
3725
await mainTab.po.signIn.goTo();
3826
await mainTab.po.signIn.setIdentifier(fakeUser.email);
3927
await mainTab.po.signIn.continue();

packages/clerk-js/src/core/auth/AuthCookieService.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { isBrowserOnline } from '@clerk/shared/browser';
21
import { createCookieHandler } from '@clerk/shared/cookie';
32
import { setDevBrowserJWTInURL } from '@clerk/shared/devBrowser';
43
import { is4xxError, isClerkAPIResponseError, isNetworkError } from '@clerk/shared/error';
54
import type { Clerk, InstanceType } from '@clerk/types';
65

7-
import { createOfflineScheduler } from '../../utils/offlineScheduler';
86
import { clerkCoreErrorTokenRefreshFailed, clerkMissingDevBrowserJwt } from '../errors';
97
import { eventBus, events } from '../events';
108
import type { FapiClient } from '../fapiClient';
@@ -41,7 +39,6 @@ export class AuthCookieService {
4139
private sessionCookie: SessionCookieHandler;
4240
private activeOrgCookie: ReturnType<typeof createCookieHandler>;
4341
private devBrowser: DevBrowser;
44-
private sessionRefreshOfflineScheduler = createOfflineScheduler();
4542

4643
public static async create(clerk: Clerk, fapiClient: FapiClient, instanceType: InstanceType) {
4744
const cookieSuffix = await getCookieSuffix(clerk.publishableKey);
@@ -128,7 +125,7 @@ export class AuthCookieService {
128125
// is updated as part of the scheduled microtask. Our existing event-based mechanism to update the cookie schedules a task, and so the cookie
129126
// is updated too late and not guaranteed to be fresh before the refetch occurs.
130127
// While online `.schedule()` executes synchronously and immediately, ensuring the above mechanism will not break.
131-
this.sessionRefreshOfflineScheduler.schedule(() => this.refreshSessionToken({ updateCookieImmediately: true }));
128+
void this.refreshSessionToken({ updateCookieImmediately: true });
132129
}
133130
});
134131
}
@@ -142,10 +139,6 @@ export class AuthCookieService {
142139
return;
143140
}
144141

145-
if (!isBrowserOnline()) {
146-
return;
147-
}
148-
149142
try {
150143
const token = await this.clerk.session.getToken();
151144
if (updateCookieImmediately) {

packages/clerk-js/src/core/clerk.ts

+5-11
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ import {
102102
} from '../utils';
103103
import { assertNoLegacyProp } from '../utils/assertNoLegacyProp';
104104
import { memoizeListenerCallback } from '../utils/memoizeStateListenerCallback';
105-
import { createOfflineScheduler } from '../utils/offlineScheduler';
106105
import { RedirectUrls } from '../utils/redirectUrls';
107106
import { AuthCookieService } from './auth/AuthCookieService';
108107
import { CaptchaHeartbeat } from './auth/CaptchaHeartbeat';
@@ -196,7 +195,6 @@ export class Clerk implements ClerkInterface {
196195
#options: ClerkOptions = {};
197196
#pageLifecycle: ReturnType<typeof createPageLifecycle> | null = null;
198197
#touchThrottledUntil = 0;
199-
#sessionTouchOfflineScheduler = createOfflineScheduler();
200198

201199
public __internal_getCachedResources:
202200
| (() => Promise<{ client: ClientJSONSnapshot | null; environment: EnvironmentJSONSnapshot | null }>)
@@ -2082,16 +2080,12 @@ export class Clerk implements ClerkInterface {
20822080
return;
20832081
}
20842082

2085-
const performTouch = () => {
2086-
if (this.#touchThrottledUntil > Date.now()) {
2087-
return;
2088-
}
2089-
this.#touchThrottledUntil = Date.now() + 5_000;
2090-
2091-
return this.#touchCurrentSession(this.session);
2092-
};
2083+
if (this.#touchThrottledUntil > Date.now()) {
2084+
return;
2085+
}
2086+
this.#touchThrottledUntil = Date.now() + 5_000;
20932087

2094-
this.#sessionTouchOfflineScheduler.schedule(performTouch);
2088+
void this.#touchCurrentSession(this.session);
20952089
});
20962090

20972091
/**

packages/clerk-js/src/utils/offlineScheduler.ts

-36
This file was deleted.

0 commit comments

Comments
 (0)