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

Check new snapshot (instead of previous) for refresh-method #1123

Merged
merged 10 commits into from
May 20, 2024
2 changes: 1 addition & 1 deletion src/core/drive/page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class PageView extends View {
}

renderPage(snapshot, isPreview = false, willRender = true, visit) {
const shouldMorphPage = this.isPageRefresh(visit) && this.snapshot.shouldMorphPage
const shouldMorphPage = this.isPageRefresh(visit) && snapshot.shouldMorphPage
const rendererClass = shouldMorphPage ? MorphRenderer : PageRenderer

const renderer = new rendererClass(this.snapshot, snapshot, PageRenderer.renderElement, isPreview, willRender)
Expand Down
16 changes: 16 additions & 0 deletions src/tests/fixtures/422_morph.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<html>
<head>
<meta name="turbo-refresh-method" content="morph">
<meta name="turbo-refresh-scroll" content="preserve">

<title>Unprocessable Entity</title>
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>
</head>
<body>
<h1>Unprocessable Entity</h1>

<turbo-frame id="frame">
<h2>Frame: Unprocessable Entity</h2>
</turbo-frame>
</body>
</html>
2 changes: 1 addition & 1 deletion src/tests/fixtures/page_refresh.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ <h3>Element with Stimulus controller</h3>
<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">
<form class="unprocessable_entity" action="/__turbo/reject/morph" method="post" style="margin-top:100vh">
<input type="hidden" name="status" value="422">
<input type="submit">
</form>
Expand Down
2 changes: 2 additions & 0 deletions src/tests/functional/autofocus_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ test("autofocus from a Turbo Stream message does not leak a placeholder [id]", a
</turbo-stream>
`)
})

await expect(page.locator("#container-from-stream input")).toBeFocused()

})

test("receiving a Turbo Stream message with an [autofocus] element when an element within the document has focus", async ({ page }) => {
Expand Down
7 changes: 7 additions & 0 deletions src/tests/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ router.post("/reject/tall", (request, response) => {
response.status(parseInt(status || "422", 10)).sendFile(fixture)
})

router.post("/reject/morph", (request, response) => {
const { status } = request.body
const fixture = path.join(__dirname, `../../src/tests/fixtures/422_morph.html`)

response.status(parseInt(status || "422", 10)).sendFile(fixture)
})

router.post("/reject", (request, response) => {
const { status } = request.body
const fixture = path.join(__dirname, `../../src/tests/fixtures/${status}.html`)
Expand Down
Loading