Skip to content

Commit

Permalink
Implement refresh fix
Browse files Browse the repository at this point in the history
  • Loading branch information
klevo committed Apr 23, 2024
1 parent bfca516 commit 1521f68
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/core/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ export class Session {

refresh(url, requestId) {
const isRecentRequest = requestId && this.recentRequests.has(requestId)
if (!isRecentRequest) {
const isCurrentUrl = url === document.baseURI
if (!isRecentRequest && isCurrentUrl) {
this.visit(url, { action: "replace", shouldCacheSnapshot: false })
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/tests/functional/page_refresh_stream_action_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ test("debounce stream page refreshes", async ({ page }) => {
})

test("debounced refresh of stale URL does not hijack new location navigated to", async ({ page }) => {
await setLongerPageRefreshDebouncePeriod(page)
const urlBeforeVisit = page.url()

await page.click("#refresh button")
Expand All @@ -79,6 +80,6 @@ async function fetchRequestId(page) {
})
}

async function visitLocation(page, location) {
return page.evaluate((location) => window.Turbo.visit(location), location)
async function setLongerPageRefreshDebouncePeriod(page, period = 500) {
return page.evaluate((period) => window.Turbo.session.pageRefreshDebouncePeriod = period, period)
}

0 comments on commit 1521f68

Please sign in to comment.