diff --git a/src/core/session.ts b/src/core/session.ts index b6c194074..12c627489 100644 --- a/src/core/session.ts +++ b/src/core/session.ts @@ -210,6 +210,9 @@ export class Session } visitStarted(visit: Visit) { + if (!visit.acceptsStreamResponse) { + markAsBusy(document.documentElement) + } extendURLWithDeprecatedProperties(visit.location) if (!visit.silent) { this.notifyApplicationAfterVisitingLocation(visit.location, visit.action) @@ -217,6 +220,7 @@ export class Session } visitCompleted(visit: Visit) { + clearBusyState(document.documentElement) this.notifyApplicationAfterPageLoad(visit.getTimingMetrics()) } @@ -346,7 +350,6 @@ export class Session } notifyApplicationAfterVisitingLocation(location: URL, action: Action) { - markAsBusy(document.documentElement) return dispatch("turbo:visit", { detail: { url: location.href, action } }) } @@ -366,7 +369,6 @@ export class Session } notifyApplicationAfterPageLoad(timing: TimingData = {}) { - clearBusyState(document.documentElement) return dispatch("turbo:load", { detail: { url: this.location.href, timing }, }) diff --git a/src/tests/fixtures/visit.html b/src/tests/fixtures/visit.html index d138fd384..cbeae69d3 100644 --- a/src/tests/fixtures/visit.html +++ b/src/tests/fixtures/visit.html @@ -1,5 +1,5 @@ - + Turbo @@ -19,7 +19,9 @@

Visit


one.html


-

Stream link with ?key=value

+

Stream link with ?key=value

+ +
diff --git a/src/tests/functional/visit_tests.ts b/src/tests/functional/visit_tests.ts index e03fbc65c..73ecb1fee 100644 --- a/src/tests/functional/visit_tests.ts +++ b/src/tests/functional/visit_tests.ts @@ -7,6 +7,7 @@ import { isScrolledToTop, nextBeat, nextEventNamed, + noNextAttributeMutationNamed, readEventLogs, scrollToSelector, visitAction, @@ -187,6 +188,15 @@ test("test visits with data-turbo-stream include MIME type & search params", asy assert.equal(getSearchParam(url, "key"), "value") }) +test("test visits with data-turbo-stream do not set aria-busy", async ({ page }) => { + await page.click("#stream-link") + + assert.ok( + await noNextAttributeMutationNamed(page, "html", "aria-busy"), + "never sets [aria-busy] on the document element" + ) +}) + test("test cache does not override response after redirect", async ({ page }) => { await page.evaluate(() => { const cachedElement = document.createElement("some-cached-element") diff --git a/src/tests/helpers/page.ts b/src/tests/helpers/page.ts index 347e3eb80..498ab5d90 100644 --- a/src/tests/helpers/page.ts +++ b/src/tests/helpers/page.ts @@ -98,6 +98,15 @@ export async function nextAttributeMutationNamed( return attributeValue } +export async function noNextAttributeMutationNamed( + page: Page, + elementId: string, + attributeName: string +): Promise { + const records = await readMutationLogs(page, 1) + return !records.some(([name]) => name == attributeName) +} + export async function noNextEventNamed(page: Page, eventName: string): Promise { const records = await readEventLogs(page, 1) return !records.some(([name]) => name == eventName) diff --git a/src/tests/server.ts b/src/tests/server.ts index 49a292e8f..46610e09e 100644 --- a/src/tests/server.ts +++ b/src/tests/server.ts @@ -86,6 +86,17 @@ router.post("/messages", (request, response) => { } }) +router.get("/stream-response", (request, response) => { + const params = { ...request.body, ...request.query } + const { content, target, targets } = params + if (acceptsStreams(request)) { + response.type("text/vnd.turbo-stream.html; charset=utf-8") + response.send(targets ? renderMessageForTargets(content, targets) : renderMessage(content, target)) + } else { + response.sendStatus(422) + } +}) + router.put("/messages/:id", (request, response) => { const { content, type } = request.body const { id } = request.params