Skip to content

Commit

Permalink
Fix turbo:load firing twice after a redirect and avoid double render (
Browse files Browse the repository at this point in the history
hotwired#563)

* Avoid firing turbo:load twice after a redirect

* Fix lint violations

* Correct reference

* New API

Co-authored-by: Felipe <felipe@temporadalivre.com>
Co-authored-by: David Heinemeier Hansson <david@hey.com>
  • Loading branch information
3 people authored Jul 16, 2022
1 parent 6f35eab commit 6eb2cde
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/core/drive/visit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,12 @@ export class Visit implements FetchRequestDelegate {
if (this.state == VisitState.started) {
this.recordTimingMetric(TimingMetric.visitEnd)
this.state = VisitState.completed
this.adapter.visitCompleted(this)
this.delegate.visitCompleted(this)
this.followRedirect()

if (!this.followedRedirect) {
this.adapter.visitCompleted(this)
this.delegate.visitCompleted(this)
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/tests/functional/navigation_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,16 @@ test("test double-clicking on a link", async ({ page }) => {
assert.equal(await visitAction(page), "advance")
})

test("test does not fire turbo:load twice after following a redirect", async ({ page }) => {
page.click("#redirection-link")

await nextBeat() // 301 redirect response
await noNextEventNamed(page, "turbo:load")
await nextBeat() // 200 response
await nextBody(page)
await nextEventNamed(page, "turbo:load")
})

test("test navigating back whilst a visit is in-flight", async ({ page }) => {
page.click("#delayed-link")
await nextEventNamed(page, "turbo:before-render")
Expand Down

0 comments on commit 6eb2cde

Please sign in to comment.