-
Notifications
You must be signed in to change notification settings - Fork 435
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 7.1 - Turbo stream not handled when using form is using URL dot notation turbo_stream format #491
Comments
The code sample you've shared looks reasonable: the However, the screenshot you've shared displays How is that URL being populated? If it's from the If you aren't using Before we dig deeper into whether or not the change in behavior is due to the 7.0 to 7.1 upgrade, could you clarify what you think it causing the page's URL to change despite the |
Hi @seanpdoyle thanks for replying. So firstly to answer your question about what submits the form, I have a very simply Stimulus controller (form_controller.js) that will perform a .requestSubmit() when user performs input of a field. This isn't the cause of issue, because if I put a submit button in the form, it does the same thing. It looks like that adding .turbo_stream format to the end of the URL is the root cause of the problem. Whereas in Turbo 7.0 with the same code it worked fine. Here are the two scenarios. Turbo 7.1
I remove the .turbo_stream in the format URL, the request sends the Turbo Frame header in the request, but it returns 500 from my server, because I my controller action expecting a turbo_stream format to respond to.
Turbo 7.0 With same HTML code as first example above with the .turbo_stream format |
@acetinick thank you for sharing additional information. I think I've answered my own questions:
Since hotwired/turbo#437, Turbo guards This is a somewhat known issue (related to hotwired/turbo#480 and hotwired/turbo#385). With that being said, one immediate way to remedy the issue is to encode the request format as a query parameter instead of a URL parameter. For For That would handle the quirk of Turbo treating That should handle it for Rails applications, since the framework treats addEventListener("turbo:before-fetch-request", (event) => {
if (event.target instanceof HTMLFormElement) {
const { fetchOptions: { method, headers } } = event.detail
if (method.match(/get/i)) {
headers.Accept = [ "text/vnd.turbo-stream.html", headers.Accept ].join(", ")
}
}
}) Could you try one of those solutions out and report back with the results? A (potentially user-facing) fix for this mechanism would also resolve #185, and is worth exploring more deeply. |
Hi @seanpdoyle your solution to add a hidden field as format parameters works fine, and fixed the issue! thanks so much as we have release soon and was blocking us. So this HTML now works for submitting the form Yes, we are using Rails as our backend and the dot notation format syntax is standard, so longer term would be nice to support. It's a workaround that works and can use ongoing. i've updated issue title to reflect more the issue |
Before turbo decides to handle a link or form request, it must determine if the link is an html page. function isHTML(url) {
return !!getExtension(url).match(/^(?:|\.(?:htm|html|xhtml))$/)
} Dot notations inside directories is fine, so another solution is to end URLs with dot notations in a "/" - /vacancies.turbo_stream?query=something
+ /vacancies.turbo_stream/?query=something Do you have a suggestion on how javascript can determine in advance if the response form a URL in a form or link will respond with html or non-html media type (e.g. .json, .png, .anything)? |
hotwired/turbo#491 Regression: url params are no longer being appended
Is there any reason why this behavior is not the default? Or at least for the forms with the Something like this should be the default behavior imo addEventListener("turbo:before-fetch-request", (event) => {
if (event.target instanceof HTMLFormElement) {
const { fetchOptions: { method, headers } } = event.detail
if (method.match(/get/i) && e.target.dataset.turboStreaming === 'true') {
headers.Accept = [ "text/vnd.turbo-stream.html", headers.Accept ].join(", ")
}
}
}) |
@n-studio - This issue is about url formats, not the |
@tleish My comment was not about My comment was about the |
I have a form that does some live filtering using turbo streams in a form that does a requestSubmit() as you type. Since upgrading to Turbo 7.1 this approach seems to break and the browser renders the as text to the browser, instead of handling the turbo stream.
Downgrading to Turbo 7.0 it works fine.
Even when replacing with a submit button, the result is the same.
My UI:
After typing:
The code I using to request the turbo stream:
I also noticed that the Turbo Frame header is not inside the request headers in my console, whereas Turbo 7.0 it was sent.
The text was updated successfully, but these errors were encountered: