forked from hotwired/turbo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow customizing the element that Drive replaces
While most of the time, replacing `<body>` makes perfect sense, when working with 3rd party integrations (i.e. Stripe), there are elements injected just before the closing `</body>` tag that should not be removed between page visits. There is more detail on this issue, particularly with injected `<iframe>` elements in hotwired#305 (comment). Now, if someone wants to customize the element that is replaced by Drive, they can add `data-turbo-drive-body` to an element, and only that element will be replaced between visits.
- Loading branch information
Showing
5 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="turbo-body" content="app"> | ||
<title>Drive (with custom body)</title> | ||
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script> | ||
<script src="/src/tests/fixtures/test.js"></script> | ||
</head> | ||
<body> | ||
<h1>Drive (with custom body)</h1> | ||
|
||
<div id="app"> | ||
<div> | ||
<a id="drive" href="/src/tests/fixtures/drive_custom_body_2.html">Drive enabled link</a> | ||
</div> | ||
|
||
<p id="different-content">Drive 1</p> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="turbo-body" content="app"> | ||
<title>Drive (with custom body)</title> | ||
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script> | ||
<script src="/src/tests/fixtures/test.js"></script> | ||
</head> | ||
<body> | ||
<h1>Drive (with custom body 2)</h1> | ||
|
||
<div id="app"> | ||
<div> | ||
<a id="drive" href="/src/tests/fixtures/drive_custom_body.html">Drive enabled link</a> | ||
</div> | ||
|
||
<p id="different-content">Drive 2</p> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { test } from "@playwright/test" | ||
import { assert } from "chai" | ||
import { nextBody, pathname } from "../helpers/page" | ||
|
||
const path = "/src/tests/fixtures/drive_custom_body.html" | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto(path) | ||
}) | ||
|
||
test("test drive with a custom body element", async ({ page }) => { | ||
page.click("#drive") | ||
await nextBody(page) | ||
|
||
const h1 = await page.locator("h1") | ||
const differentContent = await page.locator("#different-content") | ||
|
||
assert.equal(pathname(page.url()), "/src/tests/fixtures/drive_custom_body_2.html") | ||
assert.equal(await h1.textContent(), "Drive (with custom body)") | ||
assert.equal(await differentContent.textContent(), "Drive 2") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters