Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/eighty-trains-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/clerk-js": patch
---

Revert offlineScheduler
12 changes: 0 additions & 12 deletions integration/tests/sign-out-smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('sign out

test('sign out through all open tabs at once', async ({ page, context }) => {
const mainTab = createTestUtils({ app, page, context });
await mainTab.page.addInitScript(() => {
/**
* Playwright may define connection incorrectly, we are overriding to null
*/
if (
navigator.onLine &&
// @ts-expect-error Cannot find `connection`
(navigator?.connection?.rtt === 0 || navigator?.downlink?.rtt === 0)
) {
Object.defineProperty(Object.getPrototypeOf(navigator), 'connection', { value: null });
}
});
await mainTab.po.signIn.goTo();
await mainTab.po.signIn.setIdentifier(fakeUser.email);
await mainTab.po.signIn.continue();
Expand Down
9 changes: 1 addition & 8 deletions packages/clerk-js/src/core/auth/AuthCookieService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { isBrowserOnline } from '@clerk/shared/browser';
import { createCookieHandler } from '@clerk/shared/cookie';
import { setDevBrowserJWTInURL } from '@clerk/shared/devBrowser';
import { is4xxError, isClerkAPIResponseError, isNetworkError } from '@clerk/shared/error';
import type { Clerk, InstanceType } from '@clerk/types';

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

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

if (!isBrowserOnline()) {
return;
}

try {
const token = await this.clerk.session.getToken();
if (updateCookieImmediately) {
Expand Down
16 changes: 5 additions & 11 deletions packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ import {
} from '../utils';
import { assertNoLegacyProp } from '../utils/assertNoLegacyProp';
import { memoizeListenerCallback } from '../utils/memoizeStateListenerCallback';
import { createOfflineScheduler } from '../utils/offlineScheduler';
import { RedirectUrls } from '../utils/redirectUrls';
import { AuthCookieService } from './auth/AuthCookieService';
import { CaptchaHeartbeat } from './auth/CaptchaHeartbeat';
Expand Down Expand Up @@ -196,7 +195,6 @@ export class Clerk implements ClerkInterface {
#options: ClerkOptions = {};
#pageLifecycle: ReturnType<typeof createPageLifecycle> | null = null;
#touchThrottledUntil = 0;
#sessionTouchOfflineScheduler = createOfflineScheduler();

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

const performTouch = () => {
if (this.#touchThrottledUntil > Date.now()) {
return;
}
this.#touchThrottledUntil = Date.now() + 5_000;

return this.#touchCurrentSession(this.session);
};
if (this.#touchThrottledUntil > Date.now()) {
return;
}
this.#touchThrottledUntil = Date.now() + 5_000;

this.#sessionTouchOfflineScheduler.schedule(performTouch);
void this.#touchCurrentSession(this.session);
});

/**
Expand Down
36 changes: 0 additions & 36 deletions packages/clerk-js/src/utils/offlineScheduler.ts

This file was deleted.