Closed brendon closed 2 weeks ago
I've reported the spam comment.
In the meantime it might be easiest to allow for providing our own fetch function?
I can work around this by doing:
const windowFetch = window.fetch
window.fetch = fetch
post(this.unlockUrlValue, { responseKind: 'turbo-stream' })
window.fetch = windowFetch
So, could you explain the use case where we need the X-Turbo-Request-Id
when making a request with request.js
?
I'm using sortable.js
and after a sort is done I want to submit a turbo request to tell everyone else (except the acting browser) to refresh their page to see the change in order. If the X-Turbo-Request-Id
isn't sent along for the ride, the browser doesn't know to ignore the page refresh turbo-stream broadcast.
That's the simplest case that can't easily be done in another way.
Plus you provide the ability to send turbo requests, so it makes sense to account for this change in behaviour from the turbo side.
I went ahead and did a PR. Hopefully it's low touch enough :)
I'm using sortable.js and after a sort is done I want to submit a turbo request to tell everyone else (except the acting browser) to refresh their page to see the change in order. If the X-Turbo-Request-Id isn't sent along for the ride, the browser doesn't know to ignore the page refresh turbo-stream broadcast.
That's the simplest case that can't easily be done in another way.
I see, so Turbo will behave this way if the turbo-stream
returned is a refresh
action, that makes sense 👍
Thanks for bringing this up, I will take a look at the PR, but I believe it should be ok using Turbo's fetch in those scenarios.
Thanks @marcelolx :) I appreciate you taking the time to review and merge the PR :)
Turbo requests now keep track of a set of the last 20 or so requests and submits an ID for each turbo request to the server so that if a response is broadcast back to browsers the initiating browser can ignore the page reload update:
https://github.com/hotwired/turbo/blob/main/src/http/fetch.js
It would be useful to hook into this functionality in
request.js
. Would you be open to that?Hopefully it's a case of just optionally importing the augmented
fetch
from the above file? I'm sure it could be complicated though :D