Skip to content

Commit

Permalink
Fix mutation of commit listing in place
Browse files Browse the repository at this point in the history
The commit listing on each patch revision started to be flaky when using
browser navigation. It seems like the `Array.sort()` call started to
reverse the order of the commit listing back to HEAD on top which isn't
what we wanted.
`Array.toReversed()` returns a fresh copy of the reversed array which is
less error prone.
  • Loading branch information
sebastinez committed Oct 21, 2024
1 parent 2b058a1 commit 5035520
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/views/repos/Cob/Revision.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@
{/if}
{#if response?.commits}
<div class="commits">
{#each response.commits.reverse() as commit}
{#each response.commits.toReversed() as commit}
<div class="commit" style:position="relative">
<div class="commit-dot" />
<CobCommitTeaser {commit} {baseUrl} {repoId} />
Expand Down
17 changes: 17 additions & 0 deletions tests/visual/desktop/cob.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,20 @@ test("failed diff loading for a specific revision", async ({ page }) => {
.waitFor();
await expect(page).toHaveScreenshot({ fullPage: true });
});

test("commit listing ordering keeping stable on browser navigation", async ({
page,
}) => {
await page.setViewportSize({ width: 1600, height: 1200 });
await page.goto(`${cobUrl}/patches`);
await page
.getByRole("link", { name: "Taking another stab at the README" })
.click();
await page
.getByRole("heading", { name: "Taking another stab at the README" })
.waitFor();
await expect(page).toHaveScreenshot({ fullPage: true });
await page.getByRole("link", { name: "Rewrite subtitle to README" }).click();
await page.goBack();
await expect(page).toHaveScreenshot({ fullPage: true });
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"exclude": ["node_modules/*", "radicle-httpd/*"],
"compilerOptions": {
"noEmit": true,
"target": "es2021",
"target": "es2023",
"module": "es2022",
"types": ["vite/client"],
"sourceMap": true,
Expand Down

0 comments on commit 5035520

Please sign in to comment.