diff --git a/news/changelog-1.11.md b/news/changelog-1.11.md index 441176619a..af57b8f2da 100644 --- a/news/changelog-1.11.md +++ b/news/changelog-1.11.md @@ -144,6 +144,7 @@ All changes included in 1.11: - ([#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. - ([#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. - ([#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. +- ([#15217](https://github.com/quarto-dev/quarto-cli/pull/15217)): Fix website listings updating twice for each click on a pagination link. ## Lua API diff --git a/src/resources/projects/website/listing/quarto-listing.js b/src/resources/projects/website/listing/quarto-listing.js index 7e2a9f4285..6006b2c2a7 100644 --- a/src/resources/projects/website/listing/quarto-listing.js +++ b/src/resources/projects/website/listing/quarto-listing.js @@ -136,9 +136,10 @@ function refreshPaginationHandlers(listingId) { ".pagination li.page-item:not(.disabled) .page.page-link" ); for (const paginationEl of paginationEls) { + // list.js's pagination plugin shows the page from its own click + // listener on the pagination list; this handler only records the hash. paginationEl.onclick = (sender) => { setPageHash(listingId, sender.target.getAttribute("data-i")); - showPage(listingId, sender.target.getAttribute("data-i")); return false; }; } diff --git a/tests/integration/playwright/tests/listing-update-handlers.spec.ts b/tests/integration/playwright/tests/listing-update-handlers.spec.ts index ff610626a5..e269a233e4 100644 --- a/tests/integration/playwright/tests/listing-update-handlers.spec.ts +++ b/tests/integration/playwright/tests/listing-update-handlers.spec.ts @@ -26,8 +26,7 @@ async function countUpdateHandlerRuns(page: Page) { }); } -// A pagination click updates the list twice (list.js and Quarto both handle -// it), so trigger exactly one update through the List.js API instead. +// Trigger exactly one update through the List.js API. async function updateRunsForOneUpdate(page: Page, listingId: string) { return page.evaluate((id) => { const w = window as any; @@ -56,5 +55,17 @@ test.describe("Listing update handlers", () => { expect(await updateRunsForOneUpdate(page, listingId)).toBe(1); }); + + test(`${listingId} updates once per pagination click`, async ({ page }) => { + await page.goto(fixture); + await countUpdateHandlerRuns(page); + + const id = `listing-${listingId}`; + await page.locator(`#${id} .pagination .page-link[data-i="2"]`).click(); + + await expect(page).toHaveURL(new RegExp(`${id}-page=2`)); + expect(await page.evaluate((id) => (window as any).updateRuns[id], id)) + .toBe(1); + }); } });