Skip to content

Commit 9a1fe37

Browse files
desiprisgclerk-cookiedimkl
authoredNov 28, 2023
fix(clerk-js): Add push/replace props & replace state when merging fragment into url (#1304)
* feat(repo): Add push and replace props to ClerkProvider * chore(repo): Add integration test for path routing on history back * fix(repo): Fix expectation in sign in page objects to be more resilient --------- Co-authored-by: Clerk Cookie <136073014+clerk-cookie@users.noreply.github.com> Co-authored-by: Dimitris Klouvas <dimitris@clerk.dev>
1 parent 86d0a58 commit 9a1fe37

File tree

20 files changed

+126
-66
lines changed

20 files changed

+126
-66
lines changed
 

‎.changeset/gold-islands-cover.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/nextjs': major
3+
---
4+
5+
Fix a bug where navigating from the sign in page to the sign up page required two back button presses to go back.

‎.changeset/smart-suns-train.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'gatsby-plugin-clerk': major
3+
'@clerk/clerk-js': major
4+
'@clerk/nextjs': major
5+
'@clerk/remix': major
6+
'@clerk/types': major
7+
---
8+
9+
Use the new `routerPush` and `routerReplace` props for `<ClerkProvider />` instead of `navigate`.

‎.changeset/stupid-suits-accept.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/types': major
3+
---
4+
5+
Introduces two new props for `<ClerkProvider />`, `push` and `replace`. These props replace the `navigate` prop. Passing both `push` and `replace` will allow Clerk to correctly handle navigations without causing issues with the host application's router.

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const Root = () => {
1616
// @ts-ignore
1717
publishableKey={import.meta.env.VITE_CLERK_PUBLISHABLE_KEY as string}
1818
clerkJSUrl={import.meta.env.VITE_CLERK_JS as string}
19-
navigate={(to: string) => navigate(to)}
19+
routerPush={(to: string) => navigate(to)}
20+
routerReplace={(to: string) => navigate(to, { replace: true })}
2021
>
2122
<Outlet />
2223
</ClerkProvider>

‎integration/testUtils/signInPageObject.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export const createSignInComponentPageObject = (testArgs: TestArgs) => {
2323
},
2424
setInstantPassword: async (val: string) => {
2525
const passField = self.getPasswordInput();
26-
await passField.fill(val, { force: true });
2726
await expect(passField).toBeVisible();
27+
await passField.fill(val, { force: true });
2828
},
2929
getGoToSignUp: () => {
3030
return page.getByRole('link', { name: /sign up/i });
@@ -42,7 +42,10 @@ export const createSignInComponentPageObject = (testArgs: TestArgs) => {
4242
return page.getByRole('button', { name: new RegExp(`continue with ${provider}`, 'gi') });
4343
},
4444
signInWithEmailAndInstantPassword: async (opts: { email: string; password: string }) => {
45-
await self.getIdentifierInput().fill(opts.email);
45+
const identifierField = self.getIdentifierInput();
46+
await expect(identifierField).toBeVisible();
47+
48+
await identifierField.fill(opts.email);
4649
await self.setInstantPassword(opts.password);
4750
await self.continue();
4851
},

‎integration/tests/navigation.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,18 @@ export default function Page() {
197197
await u.page.getByText(/Add an email address/i).click();
198198
await u.page.getByText(/Cancel/i).click();
199199
});
200+
201+
test('sign in with path routing navigates to previous page', async ({ page, context }) => {
202+
const u = createTestUtils({ app, page, context });
203+
await u.po.signIn.goTo();
204+
await u.po.signIn.waitForMounted();
205+
206+
await u.po.signIn.getGoToSignUp().click();
207+
await u.po.signUp.waitForMounted();
208+
await u.page.waitForURL(`${app.serverUrl}/sign-up?redirect_url=${encodeURIComponent(app.serverUrl + '/')}`);
209+
210+
await page.goBack();
211+
await u.po.signIn.waitForMounted();
212+
await u.page.waitForURL(`${app.serverUrl}/sign-in`);
213+
});
200214
});

‎packages/chrome-extension/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ function ClerkProviderWithRoutes() {
6868
return (
6969
<ClerkProvider
7070
publishableKey={publishableKey}
71-
navigate={to => navigate(to)}
71+
routerPush={to => navigate(to)}
72+
routerReplace={to => navigate(to, { replace: true })}
7273
>
7374
<Routes>
7475
<Route

‎packages/clerk-js/src/core/clerk.redirects.test.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ describe('Clerk singleton - Redirects', () => {
115115

116116
clerkForProductionInstance = new Clerk(productionPublishableKey);
117117
await clerkForProductionInstance.load({
118-
navigate: mockNavigate,
118+
routerPush: mockNavigate,
119119
});
120120

121121
clerkForDevelopmentInstance = new Clerk(developmentPublishableKey);
122122
await clerkForDevelopmentInstance.load({
123-
navigate: mockNavigate,
123+
routerPush: mockNavigate,
124124
});
125125
});
126126

@@ -193,12 +193,12 @@ describe('Clerk singleton - Redirects', () => {
193193

194194
clerkForProductionInstance = new Clerk(productionPublishableKey);
195195
await clerkForProductionInstance.load({
196-
navigate: mockNavigate,
196+
routerPush: mockNavigate,
197197
});
198198

199199
clerkForDevelopmentInstance = new Clerk(developmentPublishableKey);
200200
await clerkForDevelopmentInstance.load({
201-
navigate: mockNavigate,
201+
routerPush: mockNavigate,
202202
});
203203
});
204204

@@ -284,12 +284,12 @@ describe('Clerk singleton - Redirects', () => {
284284

285285
clerkForProductionInstance = new Clerk(productionPublishableKey);
286286
await clerkForProductionInstance.load({
287-
navigate: mockNavigate,
287+
routerPush: mockNavigate,
288288
});
289289

290290
clerkForDevelopmentInstance = new Clerk(developmentPublishableKey);
291291
await clerkForDevelopmentInstance.load({
292-
navigate: mockNavigate,
292+
routerPush: mockNavigate,
293293
});
294294
});
295295

@@ -317,12 +317,12 @@ describe('Clerk singleton - Redirects', () => {
317317

318318
clerkForProductionInstance = new Clerk(productionPublishableKey);
319319
await clerkForProductionInstance.load({
320-
navigate: mockNavigate,
320+
routerPush: mockNavigate,
321321
});
322322

323323
clerkForDevelopmentInstance = new Clerk(developmentPublishableKey);
324324
await clerkForDevelopmentInstance.load({
325-
navigate: mockNavigate,
325+
routerPush: mockNavigate,
326326
});
327327
});
328328

0 commit comments

Comments
 (0)
Please sign in to comment.