Skip to content

Commit cd95d21

Browse files
authored
Stop listing pagination clicks from updating the list twic (#15217)
A click on a page link in a website listing ran list.update() twice, so every "updated" handler ran twice per click. Quarto's link onclick called showPage() on top of list.js's own pagination click listener, which also shows the page. The onclick now only records the page in the URL hash and leaves showing the page to list.js. See #15214
1 parent ce0d8af commit cd95d21

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎news/changelog-1.11.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ All changes included in 1.11:
144144
- ([#15091](https://github.com/quarto-dev/quarto-cli/pull/15091)): Fix `open-graph: false` or `twitter-card: false` in page front matter or `_metadata.yml` not disabling Open Graph or Twitter Card metadata for that page when the website enables it.
145145
- ([#15114](https://github.com/quarto-dev/quarto-cli/pull/15114)): Fix a website category containing backticks showing broken text in the page title block, and a category containing a backslash, such as a Windows path, failing the render or losing its backslashes.
146146
- ([#15206](https://github.com/quarto-dev/quarto-cli/issues/15206)): Fix website listings attaching another update handler on every URL hash change, and an extra one per additional listing on the same page.
147+
- ([#15217](https://github.com/quarto-dev/quarto-cli/pull/15217)): Fix website listings updating twice for each click on a pagination link.
147148

148149
## Lua API
149150

‎src/resources/projects/website/listing/quarto-listing.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ function refreshPaginationHandlers(listingId) {
136136
".pagination li.page-item:not(.disabled) .page.page-link"
137137
);
138138
for (const paginationEl of paginationEls) {
139+
// list.js's pagination plugin shows the page from its own click
140+
// listener on the pagination list; this handler only records the hash.
139141
paginationEl.onclick = (sender) => {
140142
setPageHash(listingId, sender.target.getAttribute("data-i"));
141-
showPage(listingId, sender.target.getAttribute("data-i"));
142143
return false;
143144
};
144145
}

‎tests/integration/playwright/tests/listing-update-handlers.spec.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ async function countUpdateHandlerRuns(page: Page) {
2626
});
2727
}
2828

29-
// A pagination click updates the list twice (list.js and Quarto both handle
30-
// it), so trigger exactly one update through the List.js API instead.
29+
// Trigger exactly one update through the List.js API.
3130
async function updateRunsForOneUpdate(page: Page, listingId: string) {
3231
return page.evaluate((id) => {
3332
const w = window as any;
@@ -56,5 +55,17 @@ test.describe("Listing update handlers", () => {
5655

5756
expect(await updateRunsForOneUpdate(page, listingId)).toBe(1);
5857
});
58+
59+
test(`${listingId} updates once per pagination click`, async ({ page }) => {
60+
await page.goto(fixture);
61+
await countUpdateHandlerRuns(page);
62+
63+
const id = `listing-${listingId}`;
64+
await page.locator(`#${id} .pagination .page-link[data-i="2"]`).click();
65+
66+
await expect(page).toHaveURL(new RegExp(`${id}-page=2`));
67+
expect(await page.evaluate((id) => (window as any).updateRuns[id], id))
68+
.toBe(1);
69+
});
5970
}
6071
});

0 commit comments

Comments
 (0)