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: Turbo stream link setting the src of a turbo frame container #968

Merged
merged 1 commit into from
Sep 13, 2023
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
2 changes: 1 addition & 1 deletion src/observers/form_link_click_observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class FormLinkClickObserver {
willFollowLinkToLocation(link, location, originalEvent) {
return (
this.delegate.willSubmitFormLinkToLocation(link, location, originalEvent) &&
link.hasAttribute("data-turbo-method")
(link.hasAttribute("data-turbo-method") || link.hasAttribute("data-turbo-stream"))
)
}

Expand Down
13 changes: 13 additions & 0 deletions src/tests/functional/frame_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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")

Expand Down