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

Frames: Abort prior requests during navigation #418

Merged
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
7 changes: 6 additions & 1 deletion src/core/frames/frame_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class FrameController implements AppearanceObserverDelegate, FetchRequest
readonly formInterceptor: FormInterceptor
currentURL?: string | null
formSubmission?: FormSubmission
private currentFetchRequest: FetchRequest | null = null
private resolveVisitPromise = () => {}
private connected = false
private hasBeenLoaded = false
Expand Down Expand Up @@ -233,11 +234,15 @@ export class FrameController implements AppearanceObserverDelegate, FetchRequest
// Private

private async visit(url: Locatable) {
const request = new FetchRequest(this, FetchMethod.get, expandURL(url), undefined, this.element)
const request = new FetchRequest(this, FetchMethod.get, expandURL(url), new URLSearchParams, this.element)

this.currentFetchRequest?.cancel()
this.currentFetchRequest = request

return new Promise<void>(resolve => {
this.resolveVisitPromise = () => {
this.resolveVisitPromise = () => {}
this.currentFetchRequest = null
resolve()
}
request.perform()
Expand Down
1 change: 1 addition & 0 deletions src/tests/fixtures/frames.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>Frames</h1>
<turbo-frame id="frame" data-loaded-from="/src/tests/fixtures/frames.html">
<h2>Frames: #frame</h2>
</turbo-frame>
<a id="outside-frame-form" href="/src/tests/fixtures/frames/form.html" data-turbo-frame="frame">Navigate #frame to /frames/form.html</a>

<turbo-frame id="hello" target="frame">
<h2>Frames: #hello</h2>
Expand Down
9 changes: 9 additions & 0 deletions src/tests/functional/frame_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export class FrameTests extends TurboDriveTestCase {
this.assert.equal(await frameText.getVisibleText(), "Frame: Loaded")
}

async "test following a link in rapid succession cancels the previous request"() {
await this.clickSelector("#outside-frame-form")
await this.clickSelector("#outer-frame-link")
await this.nextBeat

const frameText = await this.querySelector("#frame h2")
this.assert.equal(await frameText.getVisibleText(), "Frame: Loaded")
}

async "test following a link within a descendant frame whose ancestor declares a target set navigates the descendant frame"() {
const link = await this.querySelector("#nested-root[target=frame] #nested-child a:not([data-turbo-frame])")
const href = await link.getProperty("href")
Expand Down