Skip to content

Commit

Permalink
Ensure page refreshes cause a reload when assets change (#1146)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Fernández-Capel authored Jan 31, 2024
1 parent c740fc5 commit 063d556
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/drive/morph_renderer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Idiomorph } from "idiomorph/dist/idiomorph.esm.js"
import { dispatch } from "../../util"
import { Renderer } from "../renderer"
import { PageRenderer } from "./page_renderer"

export class MorphRenderer extends Renderer {
export class MorphRenderer extends PageRenderer {
async render() {
if (this.willRender) await this.#morphBody()
}
Expand Down
11 changes: 11 additions & 0 deletions src/tests/fixtures/page_refresh.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@
target.textContent = "connected"
}
})

document.getElementById("add-new-assets").addEventListener("click", () => {
const stylesheet = document.createElement("link")
stylesheet.id = "new-stylesheet"
stylesheet.rel = "stylesheet"
stylesheet.href = "/src/tests/fixtures/stylesheets/common.css"
stylesheet.dataset.turboTrack = "reload"
document.head.appendChild(stylesheet)
})
</script>

<style>
Expand Down Expand Up @@ -105,6 +114,8 @@ <h3>Element with Stimulus controller</h3>
<input id="form-submit" type="submit" value="form[method=post]">
</form>

<button id="add-new-assets">Add new assets</button>

<div id="reject">
<form class="unprocessable_entity" action="/__turbo/reject" method="post" style="margin-top:100vh">
<input type="hidden" name="status" value="422">
Expand Down
10 changes: 10 additions & 0 deletions src/tests/functional/page_refresh_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ test("turbo:before-morph-attribute Stimulus listeners can handle morphing attrib
await expect(page.locator("#test-output")).toHaveText("connected")
})

test("page refreshes cause a reload when assets change", async ({ page }) => {
await page.goto("/src/tests/fixtures/page_refresh.html")

await page.click("#add-new-assets")
await expect(page.locator("#new-stylesheet")).toHaveCount(1)
await page.click("#form-submit")

await nextEventNamed(page, "turbo:load")
await expect(page.locator("#new-stylesheet")).toHaveCount(0)
})

test("renders a page refresh with morphing when the paths are the same but search params are different", async ({ page }) => {
await page.goto("/src/tests/fixtures/page_refresh.html")
Expand Down

0 comments on commit 063d556

Please sign in to comment.