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

Ensure page refreshes cause a reload when assets change #1146

Merged
merged 1 commit into from
Jan 31, 2024
Merged
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
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 @@ -98,6 +107,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 @@ -73,6 +73,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
Loading