Skip to content

Cache text and json after reading #21

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

Merged
merged 1 commit into from
Jun 11, 2021

Conversation

excid3
Copy link
Contributor

@excid3 excid3 commented Jun 10, 2021

This saves the text and json values after reading. Fetch responses don't allow you to read these twice, so it's best if we memoize the results to prevent users from running into this.

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

Most importantly, we need memoization so you can still read the response text after the Turbo Stream messages are read and rendered.

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

Fixes #19

@marcelolx marcelolx merged commit 775f1eb into rails:main Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memoize text, html, json on response?
2 participants