Skip to content

Commit 5c8bc09

Browse files
Keep AnimateView group morph with custom values; gate view tests in Playwright
Custom enter/exit/share/update values now only replace the browser's old/new crossfade, leaving the group (position/size) animation running with Motion timing, as documented. Cypress' Electron lacks startViewTransition, so the behavioural cases skip there and are covered by a new Playwright react-19 project instead. Also publish the animate-view subpath package.json stubs. Co-authored-by: Cursor <[email protected]>
1 parent 12018e8 commit 5c8bc09

8 files changed

Lines changed: 305 additions & 20 deletions

File tree

‎dev/react/src/tests/animate-view.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function App() {
2626
const mode = new URLSearchParams(location.search).get("mode") || "default"
2727
const supported = !!(React as any).ViewTransition
2828
const custom = mode === "custom"
29+
const share = mode === "share" || mode === "share-custom"
2930

3031
return (
3132
<>
@@ -41,14 +42,19 @@ export function App() {
4142
</button>
4243
<pre id="events" />
4344
<Boundary>
44-
{((supported && (mode === "share" || mode === "update")) ||
45+
{((supported && (share || mode === "update")) ||
4546
step % 2 === 1) && (
4647
<AnimateView
4748
key={mode === "update" ? "update" : step}
48-
name={mode === "share" ? "shared" : undefined}
49+
name={share ? "shared" : undefined}
4950
transition={{ duration: 0.4, ease: "linear" }}
5051
enter={custom ? { opacity: [0, 1] } : undefined}
5152
exit={custom ? { opacity: [1, 0] } : undefined}
53+
share={
54+
mode === "share-custom"
55+
? { opacity: [1, 0.5, 1] }
56+
: undefined
57+
}
5258
onAnimationStart={(animation, type) => {
5359
const output = document.getElementById("events")!
5460
const animations = (animation as any).animations

‎packages/framer-motion/.npmignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
!dom/mini/package.json
77
!m/package.json
88
!mini/package.json
9-
!client/package.json
9+
!client/package.json
10+
!animate-view/package.json

‎packages/framer-motion/cypress/integration/animate-view.ts‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,22 @@ describe("AnimateView entry point", () => {
2121
})
2222
})
2323

24+
/**
25+
* These cases need a browser with startViewTransition. Cypress' bundled
26+
* Electron doesn't have it, so they skip here and are gated by the
27+
* Playwright spec in tests/react/animate-view.spec.ts instead.
28+
*/
2429
for (const mode of ["default", "custom", "share", "update"]) {
25-
it(`animates ${mode} views with Motion timing`, () => {
30+
it(`animates ${mode} views with Motion timing`, function () {
2631
cy.visit(`?test=animate-view&mode=${mode}`)
32+
cy.document().then((doc) => {
33+
if (typeof (doc as any).startViewTransition !== "function") {
34+
this.skip()
35+
}
36+
})
2737
cy.get("#supported").then(($supported) => {
2838
// React 18 exercises import safety and the version error above.
2939
if ($supported.text() !== "true") return
30-
cy.document().then((doc) => {
31-
expect(typeof (doc as any).startViewTransition).to.equal(
32-
"function"
33-
)
34-
})
3540
cy.get("#toggle").click()
3641
const type =
3742
mode === "share" || mode === "update" ? mode : "enter"

‎packages/motion-dom/src/view/__tests__/animate-view.test.ts‎

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ jest.mock("../utils/get-view-animations", () => ({
88
jest.mock("../../animation/NativeAnimation", () => ({
99
NativeAnimation: jest.fn(),
1010
}))
11+
jest.mock("../../animation/NativeAnimationWrapper", () => ({
12+
NativeAnimationWrapper: jest.fn((animation) => animation),
13+
}))
1114

1215
class ViewEffect {
16+
updateTiming = jest.fn()
1317
constructor(public pseudoElement: string) {}
1418
}
1519

@@ -28,15 +32,15 @@ beforeEach(() => {
2832
})
2933

3034
it("creates custom keyframes once even when several browser layers match", () => {
31-
const layers = ["group", "old", "new"].map((layer) => ({
35+
const [group, ...layers] = ["group", "old", "new"].map((layer) => ({
3236
effect: new ViewEffect(`::view-transition-${layer}(test)`),
3337
cancel: jest.fn(),
3438
}))
3539
const unrelated = {
3640
effect: new ViewEffect("::view-transition-new(other)"),
3741
cancel: jest.fn(),
3842
}
39-
getAnimations.mockReturnValue([...layers, unrelated])
43+
getAnimations.mockReturnValue([group, ...layers, unrelated])
4044
const cancel = jest.fn()
4145
createAnimation.mockImplementation(() => ({ cancel }))
4246
const resolve = jest.fn(() => ({ opacity: 1 }))
@@ -53,11 +57,46 @@ it("creates custom keyframes once even when several browser layers match", () =>
5357
})
5458
)
5559
layers.forEach((layer) => expect(layer.cancel).toHaveBeenCalledTimes(1))
60+
expect(group.cancel).not.toHaveBeenCalled()
5661
expect(unrelated.cancel).not.toHaveBeenCalled()
5762
cleanup()
5863
expect(cancel).toHaveBeenCalledTimes(1)
5964
})
6065

66+
it("keeps the group morph running when custom values replace the crossfade", () => {
67+
const group = {
68+
effect: new ViewEffect("::view-transition-group(test)"),
69+
cancel: jest.fn(),
70+
}
71+
const { updateTiming } = group.effect
72+
const old = {
73+
effect: new ViewEffect("::view-transition-old(test)"),
74+
cancel: jest.fn(),
75+
}
76+
getAnimations.mockReturnValue([group, old])
77+
createAnimation.mockImplementation(() => ({ cancel: jest.fn() }))
78+
79+
animateView(
80+
"test",
81+
"share",
82+
{ share: { clipPath: ["inset(0)", "inset(10%)"] } },
83+
[]
84+
)
85+
86+
expect(old.cancel).toHaveBeenCalledTimes(1)
87+
expect(group.cancel).not.toHaveBeenCalled()
88+
expect(updateTiming).toHaveBeenCalledWith(
89+
expect.objectContaining({ duration: 300 })
90+
)
91+
expect(createAnimation).toHaveBeenCalledTimes(1)
92+
expect(createAnimation).toHaveBeenCalledWith(
93+
expect.objectContaining({
94+
name: "clipPath",
95+
pseudoElement: "::view-transition-old(test)",
96+
})
97+
)
98+
})
99+
61100
it("does not report completion after React cleans up an interrupted transition", async () => {
62101
getAnimations.mockReturnValue([
63102
{

‎packages/motion-dom/src/view/animate-view.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ export function animateView(
4545
if (!info || info.layer !== name) continue
4646
hasMatchingAnimation = true
4747

48-
if (hasValues) {
48+
/**
49+
* Custom values replace the browser's crossfade (old/new layers).
50+
* The group layer carries the position/size morph, so keep it running
51+
* with Motion's timing.
52+
*/
53+
if (hasValues && info.type !== "group") {
4954
viewAnimation.cancel()
5055
} else {
5156
const transitionName = info.type === "group" ? "layout" : ""

‎packages/motion/.npmignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
!mini/package.json
77
!react/package.json
88
!react-client/package.json
9-
!react-m/package.json
9+
!react-m/package.json
10+
!react-animate-view/package.json

‎playwright.config.ts‎

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,42 @@ export default defineConfig({
3737
{
3838
name: "chromium",
3939
use: { ...devices["Desktop Chrome"] },
40+
testIgnore: /tests\/react\//,
4041
},
4142

4243
{
4344
name: "webkit",
4445
use: { ...devices["Desktop Safari"] },
46+
testIgnore: /tests\/react\//,
47+
},
48+
49+
/**
50+
* React 19 dev app. Used for React-only behaviour that needs a real
51+
* browser, e.g. view transitions, which Cypress' Electron can't run.
52+
*/
53+
{
54+
name: "react-19",
55+
testMatch: /tests\/react\/.*\.spec\.ts/,
56+
use: {
57+
...devices["Desktop Chrome"],
58+
baseURL: "http://localhost:9991/",
59+
},
4560
},
4661
],
4762

48-
/* Run your local dev server before starting the tests */
49-
webServer: {
50-
command: "yarn dev",
51-
url: "http://localhost:8000",
52-
reuseExistingServer: !process.env.CI,
53-
cwd: "./dev/html",
54-
},
63+
/* Run local dev servers before starting the tests */
64+
webServer: [
65+
{
66+
command: "yarn dev",
67+
url: "http://localhost:8000",
68+
reuseExistingServer: !process.env.CI,
69+
cwd: "./dev/html",
70+
},
71+
{
72+
command: "yarn dev",
73+
url: "http://localhost:9991",
74+
reuseExistingServer: !process.env.CI,
75+
cwd: "./dev/react-19",
76+
},
77+
],
5578
})

0 commit comments

Comments
 (0)