Skip to content

Commit 2fbdad0

Browse files
authored
fix(clerk-js): Fix layout shift when navigating after task resolution (#6265)
1 parent 7f341dc commit 2fbdad0

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

.changeset/ripe-months-stay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Fix layout shift when navigating after task resolution

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useClerk } from '@clerk/shared/react';
22
import { eventComponentMounted } from '@clerk/shared/telemetry';
3-
import { useCallback, useContext, useEffect, useState } from 'react';
3+
import { useCallback, useContext, useEffect, useRef, useState } from 'react';
44

55
import { Card } from '@/ui/elements/Card';
66
import { withCardStateProvider } from '@/ui/elements/contexts';
@@ -57,6 +57,7 @@ export const SessionTask = withCardStateProvider(() => {
5757
const signInContext = useContext(SignInContext);
5858
const signUpContext = useContext(SignUpContext);
5959
const [isNavigatingToTask, setIsNavigatingToTask] = useState(false);
60+
const currentTaskContainer = useRef<HTMLDivElement>(null);
6061

6162
const redirectUrlComplete =
6263
signInContext?.afterSignInUrl ?? signUpContext?.afterSignUpUrl ?? clerk?.buildAfterSignInUrl();
@@ -88,8 +89,12 @@ export const SessionTask = withCardStateProvider(() => {
8889

8990
if (!clerk.session?.currentTask) {
9091
return (
91-
<Card.Root>
92-
<Card.Content>
92+
<Card.Root
93+
sx={() => ({
94+
minHeight: currentTaskContainer ? currentTaskContainer.current?.offsetHeight : undefined,
95+
})}
96+
>
97+
<Card.Content sx={() => ({ flex: 1 })}>
9398
<LoadingCardContainer />
9499
</Card.Content>
95100
<Card.Footer />
@@ -98,7 +103,7 @@ export const SessionTask = withCardStateProvider(() => {
98103
}
99104

100105
return (
101-
<SessionTasksContext.Provider value={{ nextTask, redirectUrlComplete }}>
106+
<SessionTasksContext.Provider value={{ nextTask, redirectUrlComplete, currentTaskContainer }}>
102107
<SessionTaskRoutes />
103108
</SessionTasksContext.Provider>
104109
);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { PropsWithChildren } from 'react';
33
import { useEffect, useRef, useState } from 'react';
44

55
import { OrganizationListContext } from '@/ui/contexts';
6+
import { useSessionTasksContext } from '@/ui/contexts/components/SessionTasks';
67
import { Card } from '@/ui/elements/Card';
78
import { useCardState, withCardStateProvider } from '@/ui/elements/contexts';
89

@@ -103,9 +104,10 @@ const CreateOrganizationPage = ({ currentFlow }: CommonPageProps) => {
103104

104105
const FlowCard = ({ children }: PropsWithChildren) => {
105106
const card = useCardState();
107+
const { currentTaskContainer } = useSessionTasksContext();
106108

107109
return (
108-
<Card.Root>
110+
<Card.Root ref={currentTaskContainer}>
109111
<Card.Content sx={t => ({ padding: `${t.space.$8} ${t.space.$none} ${t.space.$none}` })}>
110112
<Card.Alert sx={t => ({ margin: `${t.space.$none} ${t.space.$5}` })}>{card.error}</Card.Alert>
111113
{children}

packages/clerk-js/src/ui/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export type CheckoutCtx = __internal_CheckoutProps & {
132132
export type SessionTasksCtx = {
133133
nextTask: () => Promise<void>;
134134
redirectUrlComplete?: string;
135+
currentTaskContainer: React.RefObject<HTMLDivElement> | null;
135136
};
136137

137138
export type OAuthConsentCtx = __internal_OAuthConsentProps & {

0 commit comments

Comments
 (0)