Skip to content

Commit

Permalink
Add data-turbo-visit-direction to html element
Browse files Browse the repository at this point in the history
  • Loading branch information
domchristie committed Sep 28, 2023
1 parent 3111416 commit c39c223
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/core/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export class Session {
visitStarted(visit) {
if (!visit.acceptsStreamResponse) {
markAsBusy(document.documentElement)
this.view.markVisitDirection(visit.direction)
}
extendURLWithDeprecatedProperties(visit.location)
if (!visit.silent) {
Expand All @@ -194,6 +195,7 @@ export class Session {
}

visitCompleted(visit) {
this.view.unmarkVisitDirection()
clearBusyState(document.documentElement)
this.notifyApplicationAfterPageLoad(visit.getTimingMetrics())
}
Expand Down
8 changes: 8 additions & 0 deletions src/core/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ export class View {
}
}

markVisitDirection(direction) {
this.element.setAttribute("data-turbo-visit-direction", direction)
}

unmarkVisitDirection() {
this.element.removeAttribute("data-turbo-visit-direction")
}

async renderSnapshot(renderer) {
await renderer.render()
}
Expand Down
4 changes: 3 additions & 1 deletion src/tests/functional/visit_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
readEventLogs,
scrollToSelector,
visitAction,
waitUntilSelector,
willChangeBody
} from "../helpers/page"

Expand Down Expand Up @@ -221,7 +222,8 @@ test("test Visit with network error", async ({ page }) => {
})

test("test turbo:visit direction details", async ({ page }) => {
await page.click("#same-origin-link")
page.click("#same-origin-link")
await waitUntilSelector(page, "[data-turbo-visit-direction='forward']")
let details = await nextEventNamed(page, "turbo:visit")
assert.equal(details.direction, "forward")

Expand Down

0 comments on commit c39c223

Please sign in to comment.