Skip to content

Commit

Permalink
fix(clerk-js): Replace state when merging fragment into url
Browse files Browse the repository at this point in the history
chore(clerk-js): Changeset
  • Loading branch information
desiprisg committed Jul 6, 2023
1 parent f81c4fc commit bafec05
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fair-mangos-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': minor
---

Fix a bug where clicking sign in/up would require two back button presses to return to the original page
3 changes: 2 additions & 1 deletion packages/clerk-js/src/ui/router/PathRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const PathRouter = ({ basePath, preservedParams, children }: PathRouterPr
const convertHashToPath = async () => {
if (hasUrlInFragment(window.location.hash)) {
const url = mergeFragmentIntoUrl(new URL(window.location.href));
await internalNavigate(url.href);
window.history.replaceState(window.history.state, '', url.href);
await internalNavigate(url.href); // make this navigation as well since replaceState is asynchronous
setStripped(true);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('PathRouter', () => {
beforeAll(() => {
// @ts-ignore
delete window.location;
history.replaceState = jest.fn();
});

afterAll(() => {
Expand Down

0 comments on commit bafec05

Please sign in to comment.