From 98e61ec858c5a30cd82448aeef14ac262f16bb56 Mon Sep 17 00:00:00 2001 From: BakiVernes Date: Tue, 5 Sep 2023 14:10:19 +0200 Subject: [PATCH] Fix turbo stream link setting the src of a turbo frame container --- src/observers/form_link_click_observer.ts | 2 +- src/tests/functional/frame_tests.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/observers/form_link_click_observer.ts b/src/observers/form_link_click_observer.ts index 8ea08597e..ba4cb4de2 100644 --- a/src/observers/form_link_click_observer.ts +++ b/src/observers/form_link_click_observer.ts @@ -26,7 +26,7 @@ export class FormLinkClickObserver implements LinkClickObserverDelegate { willFollowLinkToLocation(link: Element, location: URL, originalEvent: MouseEvent): boolean { return ( this.delegate.willSubmitFormLinkToLocation(link, location, originalEvent) && - link.hasAttribute("data-turbo-method") + link.hasAttribute("data-turbo-method") && link.hasAttribute("data-turbo-stream") ) } diff --git a/src/tests/functional/frame_tests.ts b/src/tests/functional/frame_tests.ts index 7d5fe2c85..63e9638a2 100644 --- a/src/tests/functional/frame_tests.ts +++ b/src/tests/functional/frame_tests.ts @@ -90,6 +90,19 @@ test("test following a link sets the frame element's [src]", async ({ page }) => assert.equal(src.searchParams.get("key"), "value", "[src] attribute encodes query parameters") }) +test("test following a link doesn't set the frame element's [src] if the link has [data-turbo-stream]", async ({ page }) => { + await page.goto("/src/tests/fixtures/form.html") + + const originalSrc = await page.getAttribute("#frame", "src"); + + await page.click("#stream-link-get-method-inside-frame"); + await nextBeat() + + const newSrc = await page.getAttribute("#frame", "src"); + + assert.equal(originalSrc, newSrc, "the turbo-frame src should not change after clicking the link"); +}) + test("test a frame whose src references itself does not infinitely loop", async ({ page }) => { await page.click("#frame-self")