Closed
Description
I was playing with this today and noticed that a fetch response doesn't allow reading the body twice. To reproduce:
const request = new FetchRequest("post", url)
const response = await request.perform()
await response.text
await response.text
// => Failed to execute 'text' on 'Response': body stream already read
And the situation that caught me was:
const request = new FetchRequest("post", url, { responseKind: "turbo-stream" })
const response = await request.perform()
await response.text
// => Failed to execute 'text' on 'Response': body stream already read
A solution is that we could memoize the text, html, json getters so that you could call this multiple times.
get text () {
return this.bodyText || (this.bodyText = this.response.text())
}
I noticed this because I tried to read the text on a Turbo Stream response. Since renderTurboStream
already accessed the text body, it seems unexpected.
Is this something worth fixing?
Metadata
Metadata
Assignees
Labels
No labels