Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a frame to navigate to previous url #263

Merged
merged 1 commit into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/core/frames/frame_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class FrameController implements AppearanceObserverDelegate, FetchRequest
readonly appearanceObserver: AppearanceObserver
readonly linkInterceptor: LinkInterceptor
readonly formInterceptor: FormInterceptor
currentURL?: string
currentURL?: string | null
formSubmission?: FormSubmission
private resolveVisitPromise = () => {}
private connected = false
Expand Down Expand Up @@ -312,6 +312,7 @@ export class FrameController implements AppearanceObserverDelegate, FetchRequest
set sourceURL(sourceURL: string | undefined) {
this.settingSourceURL = true
this.element.src = sourceURL ?? null
this.currentURL = this.element.src
this.settingSourceURL = false
}

Expand All @@ -337,7 +338,7 @@ function getFrameElementById(id: string | null) {
}
}

function activateElement(element: Element | null, currentURL?: string) {
function activateElement(element: Element | null, currentURL?: string | null) {
if (element) {
const src = element.getAttribute("src")
if (src != null && currentURL != null && urlsAreEqual(src, currentURL)) {
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()