-
Notifications
You must be signed in to change notification settings - Fork 433
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
Turbo doesn't send Turbo-Frame header when frame's src is updated #1191
Comments
Thank you for opening this issue. I've tried to reproduce it on
Unfortunately, I was not able to fail the test. Does it reflect the circumstances in which you've encountered this unexpected behavior? In case you want to try it locally, here's the block: test("setting the element's [src] navigates the frame", async ({ page }) => {
const frame = page.locator("#frame")
await expect(frame.locator("h2")).toHaveText("Frames: #frame")
await frame.evaluate((frame) => frame.src = "/src/tests/fixtures/frames/frame.html?key=value")
const { url, fetchOptions: { headers } } = await nextEventOnTarget(page, "frame", "turbo:before-fetch-request")
expect(headers["Turbo-Frame"]).toEqual("frame")
expect(pathname(url)).toEqual("/src/tests/fixtures/frames/frame.html")
expect(getSearchParam(url, "key"), "fetch request encodes query parameters").toEqual("value")
await expect(frame.locator("h2")).toHaveText("Frame: Loaded")
}) |
Thanks, Sean, I'll check that. In the meantime I created this minimal Rails app to showcase the issue. |
@steerio thank you for creating that repository! As a piece of advice, git diffs can be really useful in reproduction repositories. In its current format, that repository has a single commit that includes both Could you revise the repository so that the "Intial commit" only contains the |
All right, I've done this and made a force push to the same repo, and here is the commit with the changes. To see it in action you only need to It's worthy to note that if you downgrade turbo-rails with this change in the Gemfile, it all starts working.
|
I noticed something interesting with the demo code:
So the problem is that the InstaClick preload is used even when the final request is not exactly the same as the preload one. In our case, when the request is preloaded, Turbo expects a visit to happen (and can't have any idea about our onclick intentions), so that request is made without the header we're expecting to be present. The second click (provided that you didn't leave the link with the mouse before it) will make a proper request. I think the situation can be rectified by adding the headers to the cache key. For the time being, I'll switch it off with a meta tag - even with that fix, we'd have two requests done instead of one. |
To add a bit of an explanation: our use case is that some pages can be loaded in a modal and standalone as well. To tell these situations apart (and to give an ID to the Turbo Frame holding the content) we're using the We also try to cut down on payload sizes for larger, Turbo-heavy pages, so in case of Turbo Frame requests, we try to only render what was requested. We defined some handy helpers to help with this kind of thing:
It all worked well until turbo-rails 2 bumped the version of Turbo to v8. |
I think you're correct that pre-fetching is at the root of this behavior. In the meantime, are you able to render |
Yes, that's what I ended up doing, and it works. |
Looping in @afcapel @davidalejandroaguilar to help troubleshoot this behavior. |
Closes [hotwired#1191][] Ensure Prefetching does not share cache entries for requests with differing `Turbo-Frame:` HTTP headers. [hotwired#1191]: hotwired#1191
@steerio I've opened #1198 to try and resolve this issue. I've added tests that aim to reproduce the issue as you've described it. Unfortunately, they pass without any implementation changes. Could you provide some feedback on that PR to make those tests fail consistently? |
@seanpdoyle I don't readily have a system that would be able to run these tests (Arch has some issues with libpcre.so.3 and they didn't work on a Mac for some reason either). I'll set up a Debian in Docker, have them all pass, and see if I can write one that fails on this issue. Just by glancing over it I'd say that it probably works with frame requests that it triggers itself, i.e. even at mouseover time it knows that when clicked, it would load in a given frame. In my case there was a Stimulus controller (which could be any event listener) on the click event with custom code that would do that. This custom code simply updates the |
Have you tried adding the |
I haven't - I disabled the whole thing (which is fairly new to me, having only recently updated) via the meta tag. This looks like a nice alternative, thanks for pointing it out. |
@seanpdoyle , I have been trying with I went through debugging it in the browser and found that it is going through |
According to the documentation, when a request is made to update a Turbo Frame, the
Turbo-Frame
HTTP header should be set to the ID of that frame.This is not happening in Turbo 8.0.2 (delivered with Turbo-Rails 2.0.3).
To reproduce:
frame.src = "/some-url"
.Turbo-Frame
header.The text was updated successfully, but these errors were encountered: