diff --git a/src/core/drive/visit.js b/src/core/drive/visit.js index ec7565979..97aef6300 100644 --- a/src/core/drive/visit.js +++ b/src/core/drive/visit.js @@ -1,7 +1,7 @@ import { FetchMethod, FetchRequest } from "../../http/fetch_request" import { getAnchor } from "../url" import { PageSnapshot } from "./page_snapshot" -import { getHistoryMethodForAction, uuid, nextRepaint } from "../../util" +import { getHistoryMethodForAction, uuid } from "../../util" import { StreamMessage } from "../streams/stream_message" import { ViewTransitioner } from "./view_transitioner" @@ -419,7 +419,10 @@ export class Visit { async render(callback) { this.cancelRender() - this.frame = await nextRepaint() + await new Promise((resolve) => { + this.frame = + document.visibilityState === "hidden" ? setTimeout(() => resolve(), 0) : requestAnimationFrame(() => resolve()) + }) await callback() delete this.frame } diff --git a/src/tests/fixtures/cache_observer.html b/src/tests/fixtures/cache_observer.html index 5ad72b190..ad1b391f7 100644 --- a/src/tests/fixtures/cache_observer.html +++ b/src/tests/fixtures/cache_observer.html @@ -12,5 +12,7 @@

Cache Observer

data-turbo-temporary
data-turbo-cache=false

rendering

+

Redirection link back to here

+ diff --git a/src/tests/fixtures/visit.html b/src/tests/fixtures/visit.html index 19e40e5bb..7d246ffa3 100644 --- a/src/tests/fixtures/visit.html +++ b/src/tests/fixtures/visit.html @@ -21,6 +21,7 @@

Visit

one.html


Stream link with ?key=value

+

Link to cache observer

diff --git a/src/tests/functional/visit_tests.js b/src/tests/functional/visit_tests.js index dd0b97968..c53a2600c 100644 --- a/src/tests/functional/visit_tests.js +++ b/src/tests/functional/visit_tests.js @@ -175,6 +175,22 @@ test("cache does not override response after redirect", async ({ page }) => { assert.equal(await page.locator("some-cached-element").count(), 0) }) +test("cache does not hide temporary elements on the second visit after redirect", async ({ page }) => { + await page.click("#cache-observer-link") + await nextBeat() + await page.click("#redirect-here-link") + await nextBeat() // 301 redirect response + await nextBeat() // 200 response + + assert.equal(await page.locator("#temporary").count(), 1) + + await page.click("#redirect-here-link") + await nextBeat() // 301 redirect response + await nextBeat() // 200 response + + assert.equal(await page.locator("#temporary").count(), 1) +}) + function cancelNextVisit(page) { return cancelNextEvent(page, "turbo:before-visit") }