Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/core/frames/frame_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class FrameController {

this.element.removeAttribute("complete")
this.element.src = null
this.element.src = src
this.element.src = src || this.element.baseURI
return this.element.loaded
}

Expand Down
31 changes: 30 additions & 1 deletion src/tests/functional/frame_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ test("navigating a frame targeting _top from an outer link fires events", async
expect(otherEvents.length, "no more events").toEqual(0)
})

test("invoking .reload() re-fetches the frame's content", async ({ page }) => {
test("invoking .reload() re-fetches the content of a <turbo-frame> element with a [src] attribute", async ({ page }) => {
await page.click("#link-frame")
await nextEventOnTarget(page, "frame", "turbo:frame-load")
await page.evaluate(() => document.getElementById("frame").reload())
Expand All @@ -644,6 +644,35 @@ test("invoking .reload() re-fetches the frame's content", async ({ page }) => {
)
})

test("invoking .reload() re-fetches the content of a <turbo-frame> element without a [src] attribute", async ({ page }) => {
const frame = await page.locator("turbo-frame#frame")
const heading = await frame.locator("h2")

await expect(heading).toHaveText("Frames: #frame")

await heading.evaluate((h2) => h2.textContent = "Not yet refreshed")
await expect(heading).toHaveText("Not yet refreshed")

await frame.evaluate((element) => element.reload())
await expect(heading).toHaveText("Frames: #frame")

const dispatchedEvents = await readEventLogs(page)

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

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