Skip to content

Commit

Permalink
fix: random should create 1 history entry (#86)
Browse files Browse the repository at this point in the history
This fixes a regression introduced with the Navigation API where we did not correctly replace history entries anymore.

Co-authored-by: Sebastian <[email protected]>
  • Loading branch information
polyrainbow and polyrainbow authored Jan 8, 2025
1 parent f0bc2a4 commit 06cac1c
Showing 4 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/components/NoteAccessProvider.tsx
Original file line number Diff line number Diff line change
@@ -33,6 +33,9 @@ const NoteAccessProvider = ({
// @ts-ignore
navigation.navigate(
getAppPath(PathTemplate.START, new Map(), urlParams),
{
history: "replace",
},
);
});
} else {
2 changes: 1 addition & 1 deletion src/components/NoteView.tsx
Original file line number Diff line number Diff line change
@@ -268,7 +268,7 @@ const NoteView = ({ slug }: NoteViewProps) => {
]),
new URLSearchParams(location.search),
),
{ replace: true },
{ history: "replace" },
);
}
}
2 changes: 1 addition & 1 deletion src/hooks/useGoToNote.tsx
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ const useGoToNote = () => {

// @ts-ignore
return navigation.navigate(path, {
replace: params?.replace,
history: params?.replace ? "replace" : "push",
state: {
contentIfNewNote: params?.contentIfNewNote,
},
20 changes: 20 additions & 0 deletions tests/integration/editor.spec.ts
Original file line number Diff line number Diff line change
@@ -1103,4 +1103,24 @@ test.describe("Editor view", () => {
await expect(onlyParagraphChild).not.toHaveAttribute("href");
await expect(onlyParagraphChild).toHaveText("www.example.com");
});

test(
"opening a random note should create one history entry",
async ({ page }) => {
await page.keyboard.type("Note 1");
await page.click("#button_upload"); // save as "note-1"

await page.click("#button_random-note");
await page.click("#button_random-note");
await page.click("#button_random-note");

// history length should be 6 now:
// start, new, note-1, random, random, random

const result = await page.evaluate(() => {
return navigation.entries().map(e => e.url);
});
expect(result.length).toBe(6);
},
);
});

0 comments on commit 06cac1c

Please sign in to comment.