Skip to content

Rename meta tag used to enable view transitions to turbo-view-transition #1380

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/core/drive/page_snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class PageSnapshot extends Snapshot {
}

get prefersViewTransitions() {
return this.headSnapshot.getMetaValue("view-transition") === "same-origin"
return this.getSetting("view-transition") === "true" || this.headSnapshot.getMetaValue("view-transition") === "same-origin"
}

get shouldMorphPage() {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/fixtures/transitions/left.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<title>Left</title>
<meta name="view-transition" content="same-origin" />
<meta name="turbo-view-transition" content="true" />
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>

<style>
Expand Down
33 changes: 33 additions & 0 deletions src/tests/fixtures/transitions/left_legacy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title>Left</title>
<meta name="view-transition" content="same-origin" />
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>

<style>
.square {
display: block;
width: 100px;
height: 100px;
border-radius: 6px;
background-color: blue;
view-transition-name: square;
}

.square.right {
margin-left: auto;
}
</style>
</head>

<body style="background-color: orange">
<h1>Left</h1>
<p><a id="go-right" href="/src/tests/fixtures/transitions/right_legacy.html">go right</a></p>
<div class="square"></div>
<p><a id="go-other" href="/src/tests/fixtures/transitions/other.html">go other</a></p>
</body>

</html>
2 changes: 1 addition & 1 deletion src/tests/fixtures/transitions/right.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>Right</title>
<meta name="view-transition" content="same-origin" />
<meta name="turbo-view-transition" content="true" />
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>

<style>
Expand Down
32 changes: 32 additions & 0 deletions src/tests/fixtures/transitions/right_legacy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>Right</title>
<meta name="view-transition" content="same-origin" />
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>

<style>
.square {
display: block;
width: 100px;
height: 100px;
border-radius: 6px;
background-color: blue;
view-transition-name: square;
}

.square.right {
margin-left: auto;
}
</style>
</head>

<body style="background-color: red">
<h1>Right</h1>
<p><a id="go-left" href="/src/tests/fixtures/transitions/left_legacy.html">go left</a></p>
<div class="square right"></div>
</body>

</html>
30 changes: 30 additions & 0 deletions src/tests/functional/drive_view_transition_legacy_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { test } from "@playwright/test"
import { assert } from "chai"
import { nextBody } from "../helpers/page"

test.beforeEach(async ({ page }) => {
await page.goto("/src/tests/fixtures/transitions/left_legacy.html")

await page.evaluate(`
document.startViewTransition = (callback) => {
window.startViewTransitionCalled = true
callback()
}
`)
})

test("navigating triggers the view transition", async ({ page }) => {
await page.locator("#go-right").click()
await nextBody(page)

const called = await page.evaluate(`window.startViewTransitionCalled`)
assert.isTrue(called)
})

test("navigating does not trigger a view transition when meta tag not present", async ({ page }) => {
await page.locator("#go-other").click()
await nextBody(page)

const called = await page.evaluate(`window.startViewTransitionCalled`)
assert.isUndefined(called)
})