diff --git a/src/core/drive/visit.ts b/src/core/drive/visit.ts index 899f1ab02..7b050c1cb 100644 --- a/src/core/drive/visit.ts +++ b/src/core/drive/visit.ts @@ -140,6 +140,7 @@ export class Visit implements FetchRequestDelegate { this.state = VisitState.completed this.adapter.visitCompleted(this) this.delegate.visitCompleted(this) + this.followRedirect() } } @@ -259,8 +260,10 @@ export class Visit implements FetchRequestDelegate { followRedirect() { if (this.redirectedToLocation && !this.followedRedirect) { - this.location = this.redirectedToLocation - this.history.replace(this.redirectedToLocation, this.restorationIdentifier) + this.adapter.visitProposedToLocation(this.redirectedToLocation, { + action: 'replace', + response: this.response + }) this.followedRedirect = true } } diff --git a/src/core/native/browser_adapter.ts b/src/core/native/browser_adapter.ts index 8ca548c53..fb1af7806 100644 --- a/src/core/native/browser_adapter.ts +++ b/src/core/native/browser_adapter.ts @@ -56,7 +56,7 @@ export class BrowserAdapter implements Adapter { } visitCompleted(visit: Visit) { - visit.followRedirect() + } pageInvalidated() { diff --git a/src/tests/fixtures/navigation.html b/src/tests/fixtures/navigation.html index bac1a5421..d8e944700 100644 --- a/src/tests/fixtures/navigation.html +++ b/src/tests/fixtures/navigation.html @@ -33,6 +33,7 @@

Navigation

Cross-origin link inside SVG element

Disabled turbo-frame

autofocus.html link

+

Redirection link

Headers link

diff --git a/src/tests/functional/form_submission_tests.ts b/src/tests/functional/form_submission_tests.ts index 0edeee425..8891761cd 100644 --- a/src/tests/functional/form_submission_tests.ts +++ b/src/tests/functional/form_submission_tests.ts @@ -44,7 +44,7 @@ export class FormSubmissionTests extends TurboDriveTestCase { this.assert.notOk(await this.formSubmitted) this.assert.equal(await this.pathname, "/src/tests/fixtures/one.html") - this.assert.equal(await this.visitAction, "advance") + this.assert.equal(await this.visitAction, "replace") this.assert.equal(await this.getSearchParam("greeting"), "Hello from a form") } diff --git a/src/tests/functional/navigation_tests.ts b/src/tests/functional/navigation_tests.ts index 662e95658..0c9e6d942 100644 --- a/src/tests/functional/navigation_tests.ts +++ b/src/tests/functional/navigation_tests.ts @@ -203,6 +203,21 @@ export class NavigationTests extends TurboDriveTestCase { this.assert.ok(await this.isScrolledToSelector("#main"), "scrolled to #main") } + async "test following a redirection"() { + await this.clickSelector('#redirection-link') + await this.nextBody + this.assert.equal(await this.pathname, "/src/tests/fixtures/one.html") + this.assert.equal(await this.visitAction, "replace") + } + + async "test clicking the back button after redirection"() { + await this.clickSelector('#redirection-link') + await this.nextBody + await this.goBack() + this.assert.equal(await this.pathname, "/src/tests/fixtures/navigation.html") + this.assert.equal(await this.visitAction, "restore") + } + async "test same-page anchor visits do not trigger visit events"() { const events = [ "turbo:before-visit",