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

Fix double before-fetch-request dispatch during reload #740

Merged
merged 1 commit into from
Sep 27, 2022
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
10 changes: 10 additions & 0 deletions src/core/frames/frame_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ export class FrameController
}
}

sourceURLReloaded() {
const { src } = this.element
this.ignoringChangesToAttribute("complete", () => {
this.element.removeAttribute("complete")
})
this.element.src = null
this.element.src = src
return this.element.loaded
}

completeChanged() {
if (this.isIgnoringChangesTo("complete")) return

Expand Down
7 changes: 2 additions & 5 deletions src/elements/frame_element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface FrameElementDelegate extends LinkClickObserverDelegate, FormSub
completeChanged(): void
loadingStyleChanged(): void
sourceURLChanged(): void
sourceURLReloaded(): Promise<void>
disabledChanged(): void
loadResponse(response: FetchResponse): void
fetchResponseLoaded: (fetchResponse: FetchResponse) => void
Expand Down Expand Up @@ -63,11 +64,7 @@ export class FrameElement extends HTMLElement {
}

reload(): Promise<void> {
const { src } = this
this.removeAttribute("complete")
this.src = null
this.src = src
return this.loaded
return this.delegate.sourceURLReloaded()
}

attributeChangedCallback(name: string) {
Expand Down
19 changes: 19 additions & 0 deletions src/tests/functional/frame_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,25 @@ test("test navigating a frame targeting _top from an outer link fires events", a
assert.equal(otherEvents.length, 0, "no more events")
})

test("test invoking .reload() re-fetches the frame's content", async ({ page }) => {
await page.click("#link-frame")
await nextEventOnTarget(page, "frame", "turbo:frame-load")
await page.evaluate(() => (document.getElementById("frame") as any).reload())

const dispatchedEvents = await readEventLogs(page)

assert.deepEqual(
dispatchedEvents.map(([name, _, id]) => [id, name]),
[
["frame", "turbo:before-fetch-request"],
["frame", "turbo:before-fetch-response"],
["frame", "turbo:before-frame-render"],
["frame", "turbo:frame-render"],
["frame", "turbo:frame-load"],
]
)
})

test("test following inner link reloads frame on every click", async ({ page }) => {
await page.click("#hello a")
await nextEventNamed(page, "turbo:before-fetch-request")
Expand Down