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

Call Visit#fail when reloading due to request failure #1332

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/core/native/browser_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ export class BrowserAdapter {
case SystemStatusCode.networkFailure:
case SystemStatusCode.timeoutFailure:
case SystemStatusCode.contentTypeMismatch:
return this.reload({
this.reload({
reason: "request_failed",
context: {
statusCode
}
})
return visit.fail()
default:
return visit.loadResponse()
}
Expand Down
1 change: 1 addition & 0 deletions src/tests/fixtures/rendering.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ <h1>Rendering</h1>
<p><a id="delayed-link" href="/__turbo/delayed_response">Delayed link</a></p>
<p><a id="redirect-link" href="/__turbo/redirect">Redirect link</a></p>
<p><a id="es_locale_link" href="/src/tests/fixtures/es_locale.html">Change html[lang]</a></p>
<p><a id="download-link" href="/__turbo/download">Download link</a></p>
<form>
<input type="text" id="text-input">
<input type="radio" id="radio-input">
Expand Down
13 changes: 12 additions & 1 deletion src/tests/functional/rendering_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { assert } from "chai"
import {
clearLocalStorage,
disposeAll,
hasSelector,
isScrolledToTop,
nextBeat,
nextBody,
Expand All @@ -17,7 +18,8 @@ import {
sleep,
strictElementEquals,
textContent,
visitAction
visitAction,
waitUntilNoSelector,
} from "../helpers/page"

test.beforeEach(async ({ page }) => {
Expand Down Expand Up @@ -580,6 +582,15 @@ test("rendering a redirect response replaces the body once and only once", async
assert.ok(await noNextBodyMutation(page), "replaces <body> element once")
})


test.only("hides progress bar when reloading due to request failure", async ({ page }) => {
await page.click("#download-link")
await page.waitForEvent('download')

await waitUntilNoSelector(page, ".turbo-progress-bar")
assert.notOk(await hasSelector(page, ".turbo-progress-bar"), "hides progress bar")
})

function deepElementsEqual(page, left, right) {
return page.evaluate(
([left, right]) => left.length == right.length && left.every((element) => right.includes(element)),
Expand Down
4 changes: 4 additions & 0 deletions src/tests/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ router.get("/file.unknown_html", (request, response) => {
response.sendFile(path.join(__dirname, "../../src/tests/fixtures/visit.html"))
})

router.get("/download", (request, response) => {
response.download(path.join(__dirname, "../../src/tests/fixtures/svg.svg"))
})

function receiveMessage(content, id, target) {
const data = renderSSEData(renderMessage(content, id, target))
for (const response of streamResponses) {
Expand Down