Skip to content

Commit

Permalink
Allow a frame to navigate to previous url
Browse files Browse the repository at this point in the history
  • Loading branch information
t27duck committed May 1, 2021
1 parent aae03ad commit 318ada9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/frames/frame_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export class FrameController implements AppearanceObserverDelegate, FetchRequest

set sourceURL(sourceURL: string | undefined) {
this.settingSourceURL = true
this.currentURL = sourceURL
this.element.src = sourceURL ?? null
this.settingSourceURL = false
}
Expand Down
3 changes: 3 additions & 0 deletions src/tests/fixtures/frames.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ <h2>Frames: #nested-child</h2>
</turbo-frame>

<a id="frame-self" href="/src/tests/fixtures/frames/self.html" data-turbo-frame="frame">Visit self.html</a>

<a id="navigate-form-redirect" href="/src/tests/fixtures/frames/form-redirect.html" data-turbo-frame="form-redirect">Visit form-redirect.html</a>
<turbo-frame id="form-redirect"></turbo-frame>
</body>
</html>
20 changes: 20 additions & 0 deletions src/tests/fixtures/frames/form-redirect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Frame</title>
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>
<script src="/src/tests/fixtures/test.js"></script>
</head>
<body>
<h1>Page One Form</h1>
<turbo-frame id="form-redirect">
<h2 id="form-redirect-header">Form Redirect</h2>

<form action="/__turbo/redirect" method="post" enctype="multipart/form-data">
<input type="hidden" name="path" value="/src/tests/fixtures/frames/form-redirected.html">
<input type="submit" id="submit-form">
</form>
</turbo-frame>
</body>
</html>
15 changes: 15 additions & 0 deletions src/tests/fixtures/frames/form-redirected.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Frame</title>
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>
<script src="/src/tests/fixtures/test.js"></script>
</head>
<body>
<h1>Form Redirected</h1>
<turbo-frame id="form-redirect">
<h2 id="form-redirected-header">Form Redirected</h2>
</turbo-frame>
</body>
</html>
17 changes: 17 additions & 0 deletions src/tests/functional/frame_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,23 @@ export class FrameTests extends TurboDriveTestCase {

await this.nextEventNamed("turbo:before-fetch-request")
}

async "test redirecting in a form is still navigatable after redirect"() {
await this.nextBeat
await this.clickSelector("#navigate-form-redirect")
await this.nextBeat
this.assert.ok(await this.querySelector("#form-redirect"))

await this.nextBeat
await this.clickSelector("#submit-form")
await this.nextBeat
this.assert.ok(await this.querySelector("#form-redirected-header"))

await this.nextBeat
await this.clickSelector("#navigate-form-redirect")
await this.nextBeat
this.assert.ok(await this.querySelector("#form-redirect-header"))
}
}

FrameTests.registerSuite()

0 comments on commit 318ada9

Please sign in to comment.