Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache snapshot before doing page refresh #1188

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/core/drive/visit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
}
Expand Down
1 change: 0 additions & 1 deletion src/core/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" })
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/tests/functional/page_refresh_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
Loading