Skip to content
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

Allow Turbo Streams with GET requests #621

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/core/drive/form_submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { FetchRequest, FetchMethod, fetchMethodFromString, FetchRequestHeaders }
import { FetchResponse } from "../../http/fetch_response"
import { expandURL } from "../url"
import { dispatch } from "../../util"
import { StreamMessage } from "../streams/stream_message"

export interface FormSubmissionDelegate {
formSubmissionStarted(formSubmission: FormSubmission): void
Expand Down Expand Up @@ -153,7 +152,6 @@ export class FormSubmission {
if (token) {
headers["X-CSRF-Token"] = token
}
headers["Accept"] = [StreamMessage.contentType, headers["Accept"]].join(", ")
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/http/fetch_request.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FetchResponse } from "./fetch_response"
import { FrameElement } from "../elements/frame_element"
import { dispatch } from "../util"
import { StreamMessage } from "../core/streams/stream_message"

export interface FetchRequestDelegate {
referrer?: URL
Expand Down Expand Up @@ -137,7 +138,7 @@ export class FetchRequest {

get defaultHeaders() {
return {
Accept: "text/html, application/xhtml+xml",
Accept: [StreamMessage.contentType, "text/html", "application/xhtml+xml"].join(", "),
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/tests/functional/form_submission_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class FormSubmissionTests extends TurboDriveTestCase {

const { fetchOptions } = await this.nextEventNamed("turbo:before-fetch-request")

this.assert.notOk(fetchOptions.headers["Accept"].includes("text/vnd.turbo-stream.html"))
this.assert.ok(fetchOptions.headers["Accept"].includes("text/vnd.turbo-stream.html"))

await this.nextEventNamed("turbo:before-fetch-response")

Expand Down Expand Up @@ -486,7 +486,7 @@ export class FormSubmissionTests extends TurboDriveTestCase {

const { fetchOptions } = await this.nextEventNamed("turbo:before-fetch-request")

this.assert.notOk(fetchOptions.headers["Accept"].includes("text/vnd.turbo-stream.html"))
this.assert.ok(fetchOptions.headers["Accept"].includes("text/vnd.turbo-stream.html"))
this.assert.equal("frame", fetchOptions.headers["Turbo-Frame"])

await this.nextEventNamed("turbo:before-fetch-response")
Expand Down