Skip to content

Commit

Permalink
Hide Progress bar on turbo:load
Browse files Browse the repository at this point in the history
Closes [hotwired#962][]

Prior to this commit, the progress bar is hidden between the Turbo Drive
visits' `turbo:before-fetch-response` event and the `turbo:render`
event.

This commit changes that behavior to hide the bar when the Visit is
complete (some time prior to the `turbo:load` event).

[hotwired#962]: hotwired#962
  • Loading branch information
seanpdoyle committed Oct 12, 2023
1 parent c207f5b commit 9477f5f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/core/native/browser_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ export class BrowserAdapter {
}
}

visitRequestFinished(_visit) {
visitRequestFinished(_visit) {}

visitCompleted(_visit) {
this.progressBar.setValue(1)
this.hideVisitProgressBar()
}

visitCompleted(_visit) {}

pageInvalidated(reason) {
this.reload(reason)
}
Expand Down
1 change: 1 addition & 0 deletions src/tests/fixtures/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ <h1>Navigation</h1>
</turbo-toggle>
</p>
<p><a id="delayed-link" href="/__turbo/delayed_response">Delayed link</a></p>
<p><a id="delayed-failure-link" href="/__turbo/delayed_response?status=500">Delayed failure link</a></p>
<p><a id="link-target-iframe" href="/src/tests/fixtures/one.html" target="iframe">Targets iframe[name="iframe"]</a></p>
<p><a id="link-target-empty-name-iframe" href="/src/tests/fixtures/one.html" target="">Targets iframe[name=""]</a></p>
<p>
Expand Down
27 changes: 20 additions & 7 deletions src/tests/functional/navigation_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,16 @@ test.beforeEach(async ({ page }) => {
await readEventLogs(page)
})

test("test navigating renders a progress bar", async ({ page }) => {
assert.equal(
await page.locator("style").evaluate((style) => style.nonce),
"123",
"renders progress bar stylesheet inline with nonce"
)

test("test navigating renders a progress bar until the next turbo:load", async ({ page }) => {
await page.evaluate(() => window.Turbo.setProgressBarDelay(0))
await page.click("#delayed-link")

await waitUntilSelector(page, ".turbo-progress-bar")
assert.ok(await hasSelector(page, ".turbo-progress-bar"), "displays progress bar")

await nextEventNamed(page, "turbo:render")
assert.ok(await hasSelector(page, ".turbo-progress-bar"), "displays progress bar")

await nextEventNamed(page, "turbo:load")
await waitUntilNoSelector(page, ".turbo-progress-bar")

Expand All @@ -53,6 +50,22 @@ test("test navigating does not render a progress bar before expiring the delay",
assert.notOk(await hasSelector(page, ".turbo-progress-bar"), "does not show progress bar before delay")
})

test("test navigating hides the progress bar on failure", async ({ page }) => {
await page.evaluate(() => window.Turbo.setProgressBarDelay(0))
await page.click("#delayed-failure-link")

await waitUntilSelector(page, ".turbo-progress-bar")
assert.ok(await hasSelector(page, ".turbo-progress-bar"), "displays progress bar")

await nextEventNamed(page, "turbo:before-fetch-response")
assert.ok(await hasSelector(page, ".turbo-progress-bar"), "displays progress bar")

await nextEventNamed(page, "turbo:load")
await waitUntilNoSelector(page, ".turbo-progress-bar")

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

test("test after loading the page", async ({ page }) => {
assert.equal(pathname(page.url()), "/src/tests/fixtures/navigation.html")
assert.equal(await visitAction(page), "load")
Expand Down
3 changes: 2 additions & 1 deletion src/tests/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ router.get("/headers", (request, response) => {
})

router.get("/delayed_response", (request, response) => {
const { status } = request.query
const fixture = path.join(__dirname, "../../src/tests/fixtures/one.html")
setTimeout(() => response.status(200).sendFile(fixture), 1000)
setTimeout(() => response.status(parseInt(status || "200")).sendFile(fixture), 1000)
})

router.post("/messages", (request, response) => {
Expand Down

0 comments on commit 9477f5f

Please sign in to comment.