diff --git a/src/core/drive/visit.js b/src/core/drive/visit.js index 132819507..3adad253c 100644 --- a/src/core/drive/visit.js +++ b/src/core/drive/visit.js @@ -84,6 +84,7 @@ export class Visit { this.snapshotHTML = snapshotHTML this.response = response this.isSamePage = this.delegate.locationWithActionIsSamePage(this.location, this.action) + this.isPageRefresh = this.view.isPageRefresh(this) this.visitCachedSnapshot = visitCachedSnapshot this.willRender = willRender this.updateHistory = updateHistory @@ -249,7 +250,7 @@ export class Visit { const isPreview = this.shouldIssueRequest() this.render(async () => { this.cacheSnapshot() - if (this.isSamePage) { + if (this.isSamePage || this.isPageRefresh) { this.adapter.visitRendered(this) } else { if (this.view.renderPromise) await this.view.renderPromise diff --git a/src/tests/fixtures/one.html b/src/tests/fixtures/one.html index 3434d3601..5e3537c46 100644 --- a/src/tests/fixtures/one.html +++ b/src/tests/fixtures/one.html @@ -14,6 +14,7 @@

One

An element with an ID

Redirection link

+

Page refresh link

Replaced only the frame diff --git a/src/tests/fixtures/page_refresh.html b/src/tests/fixtures/page_refresh.html index d9523c6b1..69f2c6ffc 100644 --- a/src/tests/fixtures/page_refresh.html +++ b/src/tests/fixtures/page_refresh.html @@ -47,6 +47,7 @@

Element with Stimulus controller

Link with params to refresh the page

+

Link to the same page

Link to another page

diff --git a/src/tests/functional/page_refresh_tests.js b/src/tests/functional/page_refresh_tests.js index 45bb823d6..fe3ec14da 100644 --- a/src/tests/functional/page_refresh_tests.js +++ b/src/tests/functional/page_refresh_tests.js @@ -192,6 +192,20 @@ test("renders unprocessable entity responses with morphing", async ({ page }) => assert.notOk(await hasSelector(page, "#frame form.reject"), "replaces entire page") }) +test("doesn't render previews when morphing", async ({ page }) => { + await page.goto("/src/tests/fixtures/page_refresh.html") + + await page.click("#link") + await page.click("#page-refresh-link") + await page.click("#refresh-link") + await nextEventNamed(page, "turbo:render", { renderMethod: "morph" }) + await noNextEventNamed(page, "turbo:render", { renderMethod: "morph" }) + await nextBody(page) + + const title = await page.locator("h1") + assert.equal(await title.textContent(), "Page to be refreshed") +}) + async function assertPageScroll(page, top, left) { const [scrollTop, scrollLeft] = await page.evaluate(() => { return [