Skip to content

Commit 1d6061c

Browse files
committed
fix(clerk-js): Update props while respecting defaults set by Clerk.load()
Support remounting ClerkProvider multiple times by making sure that the `updateProps` call during the loading phase does not override any defaults set by `Clerk.load()` for values that are missing
1 parent ef8ef17 commit 1d6061c

4 files changed

Lines changed: 54 additions & 2 deletions

File tree

‎.changeset/cold-chicken-drop.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+
Support remounting ClerkProvider multiple times by making sure that the `updateProps` call during the loading phase does not override any defaults set by `Clerk.load()` for values that are missing

‎integration/templates/react-vite/src/main.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const Root = () => {
1515
<ClerkProvider
1616
// @ts-ignore
1717
publishableKey={import.meta.env.VITE_CLERK_PUBLISHABLE_KEY as string}
18-
clerkJSUrl={import.meta.env.VITE_CLERK_JS as string}
18+
clerkJSUrl={import.meta.env.VITE_CLERK_JS_URL as string}
1919
routerPush={(to: string) => navigate(to)}
2020
routerReplace={(to: string) => navigate(to, { replace: true })}
2121
>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { test } from '@playwright/test';
2+
3+
import type { FakeUser } from '../testUtils';
4+
import { createTestUtils, testAgainstRunningApps } from '../testUtils';
5+
6+
testAgainstRunningApps({ withPattern: ['react.vite.withEmailCodes'] })('sign in flow @generic', ({ app }) => {
7+
test.describe.configure({ mode: 'serial' });
8+
9+
let fakeUser: FakeUser;
10+
11+
test.beforeAll(async () => {
12+
const u = createTestUtils({ app });
13+
fakeUser = u.services.users.createFakeUser({
14+
fictionalEmail: true,
15+
withPassword: true,
16+
});
17+
await u.services.users.createBapiUser(fakeUser);
18+
});
19+
20+
test.afterAll(async () => {
21+
await fakeUser.deleteIfExists();
22+
await app.teardown();
23+
});
24+
25+
test('updating props after initial loading does not override defaults set by Clerk.load()', async ({
26+
page,
27+
context,
28+
}) => {
29+
const u = createTestUtils({ app, page, context });
30+
await u.po.signIn.goTo({ searchParams: new URLSearchParams({ redirect_url: 'https://www.clerk.com' }) });
31+
await u.page.waitForFunction(async () => {
32+
// Emulate ClerkProvider being unmounted and mounted again
33+
// as updateProps is going to be called without the default options set by window.Clerk.load()
34+
await (window.Clerk as any).__unstable__updateProps({ options: {} });
35+
});
36+
await u.po.signIn.setIdentifier(fakeUser.email);
37+
await u.po.signIn.continue();
38+
await u.po.signIn.setPassword(fakeUser.password);
39+
await u.po.signIn.continue();
40+
await u.po.expect.toBeSignedIn();
41+
// allowedRedirectOrigins should still be respected here
42+
// even after the above updateProps invocation
43+
await u.page.waitForURL(`${app.serverUrl}`);
44+
});
45+
});

‎packages/clerk-js/src/ui/Components.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ const Components = (props: ComponentsProps) => {
169169
nodes: new Map(),
170170
impersonationFab: false,
171171
});
172+
172173
const {
173174
googleOneTapModal,
174175
signInModal,
@@ -215,7 +216,8 @@ const Components = (props: ComponentsProps) => {
215216
return;
216217
}
217218
}
218-
setState(s => ({ ...s, ...restProps }));
219+
220+
setState(s => ({ ...s, ...restProps, options: { ...s.options, ...restProps.options } }));
219221
};
220222

221223
componentsControls.closeModal = name => {

0 commit comments

Comments
 (0)