diff --git a/src/core/session.js b/src/core/session.js index 60c64abb5..03b1ecc41 100644 --- a/src/core/session.js +++ b/src/core/session.js @@ -108,10 +108,12 @@ export class Session { } refresh(url, requestId) { + const refreshUrl = url || document.baseURI const isRecentRequest = requestId && this.recentRequests.has(requestId) + if (!isRecentRequest) { this.cache.exemptPageFromPreview() - this.visit(url, { action: "refresh" }) + this.visit(refreshUrl, { action: "refresh" }) } } diff --git a/src/tests/functional/page_refresh_tests.js b/src/tests/functional/page_refresh_tests.js index 06a041787..f6da27695 100644 --- a/src/tests/functional/page_refresh_tests.js +++ b/src/tests/functional/page_refresh_tests.js @@ -319,3 +319,10 @@ async function assertPageScroll(page, top, left) { expect(scrollTop).toEqual(top) expect(scrollLeft).toEqual(left) } + +test("Turbo.session.refresh() will refresh current page", async ({ page }) => { + await page.goto("/src/tests/fixtures/page_refresh.html") + await page.evaluate(() => window.Turbo.session.refresh()) + + await nextEventNamed(page, "turbo:render", { renderMethod: "morph" }) +}) \ No newline at end of file diff --git a/src/tests/functional/visit_tests.js b/src/tests/functional/visit_tests.js index 782871747..065ebf22c 100644 --- a/src/tests/functional/visit_tests.js +++ b/src/tests/functional/visit_tests.js @@ -256,6 +256,13 @@ test("Visit direction attribute on a replace visit", async ({ page }) => { await assertVisitDirectionAttribute(page, "none") }) +test("Visit direction when refreshing", async ({ page }) => { + page.evaluate(() => window.Turbo.session.refresh()) + + await assertVisitDirectionAttribute(page, "none") +}) + + test("Turbo history state after a reload", async ({ page }) => { await page.click("#same-origin-link") await nextEventNamed(page, "turbo:load")