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

Don't include Turbo-Frame header in promoted frame navigations #1143

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 3 additions & 1 deletion src/core/frames/frame_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ export class FrameController {
// Fetch request delegate

prepareRequest(request) {
request.headers["Turbo-Frame"] = this.id
if (!this.action) {
request.headers["Turbo-Frame"] = this.id
}

if (this.currentNavigationElement?.hasAttribute("data-turbo-stream")) {
request.acceptResponseType(StreamMessage.contentType)
Expand Down
31 changes: 31 additions & 0 deletions src/tests/functional/frame_navigation_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ test("lazy-loaded frame promotes navigation", async ({ page }) => {
assert.equal(pathname(page.url()), "/src/tests/fixtures/frames/frame_for_eager.html")
})

test("frame navigation sets the Turbo-Frame header", async ({ page }) => {
await page.goto("/src/tests/fixtures/frame_navigation.html")
assertNextRequesTurboFrameHeader(page, "frame")

await page.click("#inside")
await nextEventNamed(page, "turbo:load")
})

test("frame navigation promoted with data-turbo-target=_top doesn't set the Turbo-Frame header", async ({ page }) => {
await page.goto("/src/tests/fixtures/frame_navigation.html")
assertNextRequesTurboFrameHeader(page, undefined)

await page.click("#top")
await nextEventNamed(page, "turbo:load")
})

test("frame navigation promoted with data-turbo-action doesn't set the Turbo-Frame header", async ({ page }) => {
await page.goto("/src/tests/fixtures/tabs.html")
assertNextRequesTurboFrameHeader(page, undefined)

await page.click("#tab-1")
await nextEventNamed(page, "turbo:frame-render")
})

test("promoted frame navigation updates the URL before rendering", async ({ page }) => {
await page.goto("/src/tests/fixtures/tabs.html")

Expand Down Expand Up @@ -104,3 +128,10 @@ test("promoted frame navigations are cached", async ({ page }) => {
assert.equal(await page.getAttribute("#tab-frame", "src"), null, "caches one.html without #tab-frame[src]")
assert.equal(await page.getAttribute("#tab-frame", "complete"), null, "caches one.html without [complete]")
})

function assertNextRequesTurboFrameHeader(page, expected) {
page.on("request", (request) => {
assert.equal(request.headers()["turbo-frame"], expected)
})
}

Loading