Skip to content

Commit

Permalink
Fix turbo stream link setting the src of a turbo frame container
Browse files Browse the repository at this point in the history
  • Loading branch information
BakiVernes committed Sep 12, 2023
1 parent 9f3aad7 commit ac9d24a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/turbo.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

0 comments on commit ac9d24a

Please sign in to comment.