Skip to content

Commit 5902f95

Browse files
committed
Remove __internal_navigateToTaskIfAvailable
This is main issue with the current after-auth implementation. Navigation should happen within `setActive` due to the session state changes that could could re-render ofpages.
1 parent 90b4039 commit 5902f95

File tree

10 files changed

+13
-114
lines changed

10 files changed

+13
-114
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,7 +2471,6 @@ describe('Clerk singleton', () => {
24712471
await sut.load(mockedLoadOptions);
24722472

24732473
await sut.setActive({ session: mockResource as any as PendingSessionResource });
2474-
await sut.__internal_navigateToTaskIfAvailable();
24752474

24762475
expect(mockNavigate.mock.calls[0][0]).toBe('/sign-in#/tasks/choose-organization');
24772476
});
@@ -2486,7 +2485,6 @@ describe('Clerk singleton', () => {
24862485
});
24872486

24882487
await sut.setActive({ session: mockResource as any as PendingSessionResource });
2489-
await sut.__internal_navigateToTaskIfAvailable();
24902488

24912489
expect(mockNavigate.mock.calls[0][0]).toBe('/onboarding/choose-organization');
24922490
});
@@ -2535,7 +2533,6 @@ describe('Clerk singleton', () => {
25352533
await sut.setActive({ session: mockSession as any as ActiveSessionResource });
25362534

25372535
const redirectUrlComplete = '/welcome-to-app';
2538-
await sut.__internal_navigateToTaskIfAvailable({ redirectUrlComplete });
25392536

25402537
console.log(mockNavigate.mock.calls);
25412538

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

Lines changed: 6 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import type {
1919
__experimental_CheckoutOptions,
2020
__internal_CheckoutProps,
2121
__internal_ComponentNavigationContext,
22-
__internal_NavigateToTaskIfAvailableParams,
2322
__internal_OAuthConsentProps,
2423
__internal_PlanDetailsProps,
2524
__internal_SubscriptionDetailsProps,
@@ -30,9 +29,9 @@ import type {
3029
AuthenticateWithGoogleOneTapParams,
3130
AuthenticateWithMetamaskParams,
3231
AuthenticateWithOKXWalletParams,
33-
Clerk as ClerkInterface,
3432
ClerkAPIError,
3533
ClerkAuthenticateWithWeb3Params,
34+
Clerk as ClerkInterface,
3635
ClerkOptions,
3736
ClientJSONSnapshot,
3837
ClientResource,
@@ -1368,9 +1367,7 @@ export class Clerk implements ClerkInterface {
13681367
eventBus.emit(events.TokenUpdate, { token: null });
13691368
}
13701369

1371-
// Only triggers navigation for internal AIO components routing or custom URLs
1372-
const shouldNavigateOnSetActive = this.#componentNavigationContext;
1373-
if (newSession?.currentTask && shouldNavigateOnSetActive) {
1370+
if (newSession?.currentTask) {
13741371
await navigateToTask(session.currentTask.key, {
13751372
options: this.#options,
13761373
environment: this.environment,
@@ -1385,60 +1382,6 @@ export class Clerk implements ClerkInterface {
13851382
await onAfterSetActive();
13861383
};
13871384

1388-
public __internal_navigateToTaskIfAvailable = async ({
1389-
redirectUrlComplete,
1390-
}: __internal_NavigateToTaskIfAvailableParams = {}): Promise<void> => {
1391-
const onBeforeSetActive: SetActiveHook =
1392-
typeof window !== 'undefined' && typeof window.__unstable__onBeforeSetActive === 'function'
1393-
? window.__unstable__onBeforeSetActive
1394-
: noop;
1395-
1396-
const onAfterSetActive: SetActiveHook =
1397-
typeof window !== 'undefined' && typeof window.__unstable__onAfterSetActive === 'function'
1398-
? window.__unstable__onAfterSetActive
1399-
: noop;
1400-
1401-
const session = this.session;
1402-
if (!session || !this.environment) {
1403-
return;
1404-
}
1405-
1406-
if (session.status === 'pending') {
1407-
await navigateToTask(session.currentTask.key, {
1408-
options: this.#options,
1409-
environment: this.environment,
1410-
globalNavigate: this.navigate,
1411-
componentNavigationContext: this.#componentNavigationContext,
1412-
});
1413-
return;
1414-
}
1415-
1416-
await onBeforeSetActive();
1417-
1418-
if (redirectUrlComplete) {
1419-
const tracker = createBeforeUnloadTracker(this.#options.standardBrowser);
1420-
1421-
await tracker.track(async () => {
1422-
if (!this.client) {
1423-
return;
1424-
}
1425-
1426-
if (this.client.isEligibleForTouch()) {
1427-
const absoluteRedirectUrl = new URL(redirectUrlComplete, window.location.href);
1428-
await this.navigate(this.buildUrlWithAuth(this.client.buildTouchUrl({ redirectUrl: absoluteRedirectUrl })));
1429-
} else {
1430-
await this.navigate(redirectUrlComplete);
1431-
}
1432-
});
1433-
1434-
if (tracker.isUnloading()) {
1435-
return;
1436-
}
1437-
}
1438-
1439-
await onAfterSetActive();
1440-
};
1441-
14421385
public addListener = (listener: ListenerCallback): UnsubscribeCallback => {
14431386
listener = memoizeListenerCallback(listener);
14441387
this.#listeners.push(listener);
@@ -1909,11 +1852,10 @@ export class Clerk implements ClerkInterface {
19091852
};
19101853

19111854
if (si.status === 'complete') {
1912-
await this.setActive({
1855+
return this.setActive({
19131856
session: si.sessionId,
19141857
redirectUrl: redirectUrls.getAfterSignInUrl(),
19151858
});
1916-
return this.__internal_navigateToTaskIfAvailable();
19171859
}
19181860

19191861
const userExistsButNeedsToSignIn =
@@ -1923,11 +1865,10 @@ export class Clerk implements ClerkInterface {
19231865
const res = await signIn.create({ transfer: true });
19241866
switch (res.status) {
19251867
case 'complete':
1926-
await this.setActive({
1868+
return this.setActive({
19271869
session: res.createdSessionId,
19281870
redirectUrl: redirectUrls.getAfterSignInUrl(),
19291871
});
1930-
return this.__internal_navigateToTaskIfAvailable();
19311872
case 'needs_first_factor':
19321873
return navigateToFactorOne();
19331874
case 'needs_second_factor':
@@ -1973,11 +1914,10 @@ export class Clerk implements ClerkInterface {
19731914
const res = await signUp.create({ transfer: true });
19741915
switch (res.status) {
19751916
case 'complete':
1976-
await this.setActive({
1917+
return this.setActive({
19771918
session: res.createdSessionId,
19781919
redirectUrl: redirectUrls.getAfterSignUpUrl(),
19791920
});
1980-
return this.__internal_navigateToTaskIfAvailable();
19811921
case 'missing_requirements':
19821922
return navigateToNextStepSignUp({ missingFields: res.missingFields });
19831923
default:
@@ -1986,11 +1926,10 @@ export class Clerk implements ClerkInterface {
19861926
}
19871927

19881928
if (su.status === 'complete') {
1989-
await this.setActive({
1929+
return this.setActive({
19901930
session: su.sessionId,
19911931
redirectUrl: redirectUrls.getAfterSignUpUrl(),
19921932
});
1993-
return this.__internal_navigateToTaskIfAvailable();
19941933
}
19951934

19961935
if (si.status === 'needs_second_factor') {
@@ -2026,10 +1965,6 @@ export class Clerk implements ClerkInterface {
20261965
return navigateToNextStepSignUp({ missingFields: signUp.missingFields });
20271966
}
20281967

2029-
if (this.__internal_hasAfterAuthFlows) {
2030-
return this.__internal_navigateToTaskIfAvailable({ redirectUrlComplete: redirectUrls.getAfterSignInUrl() });
2031-
}
2032-
20331968
return navigateToSignIn();
20341969
};
20351970

packages/clerk-js/src/ui/components/SessionTasks/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const SessionTasksStart = () => {
2424
useEffect(() => {
2525
// Simulates additional latency to avoid a abrupt UI transition when navigating to the next task
2626
const timeoutId = setTimeout(() => {
27-
void clerk.__internal_navigateToTaskIfAvailable({ redirectUrlComplete });
27+
// TODO - call setActive?
2828
}, 500);
2929
return () => clearTimeout(timeoutId);
3030
}, [navigate, clerk, redirectUrlComplete]);

packages/clerk-js/src/ui/components/SessionTasks/tasks/TaskChooseOrganization/ChooseOrganizationScreen.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ export const ChooseOrganizationScreen = withCardStateProvider(
9898
const MembershipPreview = withCardStateProvider((props: { organization: OrganizationResource }) => {
9999
const card = useCardState();
100100
const { redirectUrlComplete } = useSessionTasksContext();
101-
const { __internal_navigateToTaskIfAvailable } = useClerk();
102101
const { isLoaded, setActive } = useOrganizationList();
103102

104103
if (!isLoaded) {
@@ -110,8 +109,6 @@ const MembershipPreview = withCardStateProvider((props: { organization: Organiza
110109
await setActive({
111110
organization,
112111
});
113-
114-
await __internal_navigateToTaskIfAvailable({ redirectUrlComplete });
115112
});
116113
};
117114

packages/clerk-js/src/ui/components/SessionTasks/tasks/TaskChooseOrganization/CreateOrganizationScreen.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useClerk, useOrganizationList } from '@clerk/shared/react';
1+
import { useOrganizationList } from '@clerk/shared/react';
22

33
import { useSessionTasksContext } from '@/ui/contexts/components/SessionTasks';
44
import { localizationKeys } from '@/ui/customizables';
@@ -19,7 +19,6 @@ type CreateOrganizationScreenProps = {
1919

2020
export const CreateOrganizationScreen = withCardStateProvider((props: CreateOrganizationScreenProps) => {
2121
const card = useCardState();
22-
const { __internal_navigateToTaskIfAvailable } = useClerk();
2322
const { redirectUrlComplete } = useSessionTasksContext();
2423
const { createOrganization, isLoaded, setActive } = useOrganizationList({
2524
userMemberships: organizationListParams.userMemberships,
@@ -47,8 +46,6 @@ export const CreateOrganizationScreen = withCardStateProvider((props: CreateOrga
4746
const organization = await createOrganization({ name: nameField.value, slug: slugField.value });
4847

4948
await setActive({ organization });
50-
51-
await __internal_navigateToTaskIfAvailable({ redirectUrlComplete });
5249
} catch (err) {
5350
handleError(err, [nameField, slugField], card.setError);
5451
}

packages/clerk-js/src/ui/components/UserButton/useMultisessionActions.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type UseMultisessionActionsParams = {
1919
} & Pick<UserButtonProps, 'userProfileMode' | 'appearance' | 'userProfileProps'>;
2020

2121
export const useMultisessionActions = (opts: UseMultisessionActionsParams) => {
22-
const { setActive, signOut, openUserProfile, __internal_navigateToTaskIfAvailable } = useClerk();
22+
const { setActive, signOut, openUserProfile } = useClerk();
2323
const card = useCardState();
2424
const { signedInSessions, otherSessions } = useMultipleSessions({ user: opts.user });
2525
const { navigate } = useRouter();
@@ -70,12 +70,10 @@ export const useMultisessionActions = (opts: UseMultisessionActionsParams) => {
7070
const handleSessionClicked = (session: SignedInSessionResource) => async () => {
7171
card.setLoading();
7272

73-
return setActive({ session, redirectUrl: opts.afterSwitchSessionUrl })
74-
.then(() => __internal_navigateToTaskIfAvailable())
75-
.finally(() => {
76-
card.setIdle();
77-
opts.actionCompleteCallback?.();
78-
});
73+
return setActive({ session, redirectUrl: opts.afterSwitchSessionUrl }).finally(() => {
74+
card.setIdle();
75+
opts.actionCompleteCallback?.();
76+
});
7977
};
8078

8179
const handleAddAccountClicked = () => {

packages/nextjs/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export {
1212
RedirectToOrganizationProfile,
1313
RedirectToSignIn,
1414
RedirectToSignUp,
15-
RedirectToTask,
1615
RedirectToUserProfile,
1716
} from './client-boundary/controlComponents';
1817

packages/react/src/components/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export {
2525
RedirectToOrganizationProfile,
2626
RedirectToSignIn,
2727
RedirectToSignUp,
28-
RedirectToTask,
2928
RedirectToUserProfile,
3029
SignedIn,
3130
SignedOut,

packages/react/src/isomorphicClerk.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { loadClerkJsScript } from '@clerk/shared/loadClerkJsScript';
44
import { handleValueOrFn } from '@clerk/shared/utils';
55
import type {
66
__internal_CheckoutProps,
7-
__internal_NavigateToTaskIfAvailableParams,
87
__internal_OAuthConsentProps,
98
__internal_PlanDetailsProps,
109
__internal_SubscriptionDetailsProps,
@@ -738,14 +737,6 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk {
738737
}
739738
};
740739

741-
__internal_navigateToTaskIfAvailable = async (params?: __internal_NavigateToTaskIfAvailableParams): Promise<void> => {
742-
if (this.clerkjs) {
743-
return this.clerkjs.__internal_navigateToTaskIfAvailable(params);
744-
} else {
745-
return Promise.reject();
746-
}
747-
};
748-
749740
/**
750741
* `setActive` can be used to set the active session and/or organization.
751742
*/

packages/types/src/clerk.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -830,12 +830,6 @@ export interface Clerk {
830830

831831
joinWaitlist: (params: JoinWaitlistParams) => Promise<WaitlistResource>;
832832

833-
/**
834-
* Navigates to the current task or redirects to `redirectUrlComplete` once the session is `active`.
835-
* @internal
836-
*/
837-
__internal_navigateToTaskIfAvailable: (params?: __internal_NavigateToTaskIfAvailableParams) => Promise<void>;
838-
839833
/**
840834
* This is an optional function.
841835
* This function is used to load cached Client and Environment resources if Clerk fails to load them from the Frontend API.
@@ -2127,14 +2121,6 @@ export interface AuthenticateWithGoogleOneTapParams {
21272121
legalAccepted?: boolean;
21282122
}
21292123

2130-
export interface __internal_NavigateToTaskIfAvailableParams {
2131-
/**
2132-
* Full URL or path to navigate to after successfully resolving all tasks
2133-
* @default undefined
2134-
*/
2135-
redirectUrlComplete?: string;
2136-
}
2137-
21382124
export interface LoadedClerk extends Clerk {
21392125
client: ClientResource;
21402126
}

0 commit comments

Comments
 (0)