diff --git a/src/core/drive/visit.js b/src/core/drive/visit.js index ec7565979..119308a4b 100644 --- a/src/core/drive/visit.js +++ b/src/core/drive/visit.js @@ -114,10 +114,15 @@ export class Visit { return this.isSamePage } - start() { + async start() { if (this.state == VisitState.initialized) { this.recordTimingMetric(TimingMetric.visitStart) this.state = VisitState.started + + if (this.isPageRefresh) { + await this.cacheSnapshot() + } + this.adapter.visitStarted(this) this.delegate.visitStarted(this) } @@ -410,9 +415,14 @@ export class Visit { } } - cacheSnapshot() { + async cacheSnapshot() { if (!this.snapshotCached) { - this.view.cacheSnapshot(this.snapshot).then((snapshot) => snapshot && this.visitCachedSnapshot(snapshot)) + const snapshot = await this.view.cacheSnapshot(this.snapshot) + + if (snapshot) { + this.visitCachedSnapshot(snapshot) + } + this.snapshotCached = true } } diff --git a/src/core/session.js b/src/core/session.js index eb0c9880c..1f55db65f 100644 --- a/src/core/session.js +++ b/src/core/session.js @@ -110,7 +110,6 @@ export class Session { refresh(url, requestId) { const isRecentRequest = requestId && this.recentRequests.has(requestId) if (!isRecentRequest) { - this.cache.exemptPageFromPreview() this.visit(url, { action: "replace" }) } } diff --git a/src/tests/functional/page_refresh_tests.js b/src/tests/functional/page_refresh_tests.js index 06a041787..159fe5f52 100644 --- a/src/tests/functional/page_refresh_tests.js +++ b/src/tests/functional/page_refresh_tests.js @@ -308,6 +308,13 @@ test("doesn't render previews when morphing", async ({ page }) => { assert.equal(await title.textContent(), "Page to be refreshed") }) +test("it snapshots page before starting a page refresh", async ({ page }) => { + await page.goto("/src/tests/fixtures/page_refresh.html") + + await page.click("#form-submit") + await nextEventNamed(page, "turbo:before-cache") +}) + async function assertPageScroll(page, top, left) { const [scrollTop, scrollLeft] = await page.evaluate(() => { return [