Skip to content

Commit

Permalink
Ensure that page refreshes do not trigger a snapshot cache (#1196)
Browse files Browse the repository at this point in the history
Fixes a bug introduced in #1146

`exemptPageFromPreview()` adds a `<meta>` tag to the `<head>` setting
`turbo-cache-control` to `no-preview`. However, since the MorphRenderer
now inherits from the PageRenderer, it can update meta tags in the head
and remove the `turbo-cache-control` tag. This means that the snapshot
cache will be used for the next visit, which is not what we want.

Specifying `shouldCacheSnapshot: false` in the `visit` options ensures
that the snapshot cache is not used for the refresh visit.
  • Loading branch information
Alberto Fernández-Capel committed Feb 21, 2024
1 parent 3a8e2d9 commit cdd3079
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/core/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ export class Session {
refresh(url, requestId) {
const isRecentRequest = requestId && this.recentRequests.has(requestId)
if (!isRecentRequest) {
this.cache.exemptPageFromPreview()
this.visit(url, { action: "replace" })
this.visit(url, { action: "replace", shouldCacheSnapshot: false })
}
}

Expand Down
1 change: 1 addition & 0 deletions src/tests/functional/page_refresh_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ test("async page refresh with turbo-stream", async ({ page }) => {

await expect(page.locator("#title")).not.toHaveText("Updated")
await expect(page.locator("#title")).toHaveText("Page to be refreshed")
expect(await noNextEventNamed(page, "turbo:before-cache")).toBeTruthy()
})

test("dispatches a turbo:before-morph-element and turbo:morph-element event for each morphed element", async ({ page }) => {
Expand Down

0 comments on commit cdd3079

Please sign in to comment.