diff --git a/src/core/frames/frame_controller.js b/src/core/frames/frame_controller.js index 5940ba761..ea56aeb55 100644 --- a/src/core/frames/frame_controller.js +++ b/src/core/frames/frame_controller.js @@ -94,7 +94,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 } diff --git a/src/tests/functional/frame_tests.js b/src/tests/functional/frame_tests.js index b090aff8a..610e8c232 100644 --- a/src/tests/functional/frame_tests.js +++ b/src/tests/functional/frame_tests.js @@ -515,7 +515,7 @@ test("navigating a frame targeting _top from an outer link fires events", async assert.equal(otherEvents.length, 0, "no more events") }) -test("invoking .reload() re-fetches the frame's content", async ({ page }) => { +test("invoking .reload() re-fetches the content of a 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()) @@ -523,7 +523,37 @@ test("invoking .reload() re-fetches the frame's content", async ({ page }) => { const dispatchedEvents = await readEventLogs(page) assert.deepEqual( - dispatchedEvents.map(([name, _, id]) => [id, name]), + dispatchedEvents + .map(([name, _, id]) => [id, name]) + .filter(([id]) => id === "frame"), + [ + ["frame", "turbo:before-fetch-request"], + ["frame", "turbo:before-fetch-response"], + ["frame", "turbo:before-frame-render"], + ["frame", "turbo:frame-render"], + ["frame", "turbo:frame-load"] + ] + ) +}) + +test("invoking .reload() re-fetches the content of a element without a [src] attribute", async ({ page }) => { + const frame = await page.locator("turbo-frame#frame") + const heading = await frame.locator("h2") + + assert.match(await heading.textContent(), /Frames: #frame/) + + await heading.evaluate((element) => element.textContent = "Not yet refreshed") + + assert.match(await heading.textContent(), /Not yet refreshed/) + + await frame.evaluate((element) => element.reload()) + + const dispatchedEvents = await readEventLogs(page) + + assert.deepEqual( + dispatchedEvents + .map(([name, _, id]) => [id, name]) + .filter(([id]) => id === "frame"), [ ["frame", "turbo:before-fetch-request"], ["frame", "turbo:before-fetch-response"],