Skip to content

Commit 6aba50e

Browse files
committed
Cache text and json after reading. Fixes #19
1 parent d155443 commit 6aba50e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/fetch_response.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@ export class FetchResponse {
3131

3232
get html () {
3333
if (this.contentType.match(/^(application|text)\/(html|xhtml\+xml)$/)) {
34-
return this.response.text()
34+
return this.text
3535
}
3636

3737
return Promise.reject(new Error(`Expected an HTML response but got "${this.contentType}" instead`))
3838
}
3939

4040
get json () {
4141
if (this.contentType.match(/^application\/json/)) {
42-
return this.response.json()
42+
return this.responseJson || (this.responseJson = this.response.json())
4343
}
4444

4545
return Promise.reject(new Error(`Expected a JSON response but got "${this.contentType}" instead`))
4646
}
4747

4848
get text () {
49-
return this.response.text()
49+
return this.responseText || (this.responseText = this.response.text())
5050
}
5151

5252
get isTurboStream () {

0 commit comments

Comments
 (0)