Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 32 additions & 0 deletions dev/react/src/tests/waapi-svg-zero-duration.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { motion } from "framer-motion"
import { useState } from "react"

export const App = () => {
const [hidden, setHidden] = useState(false)

return (
<>
<button id="toggle" onClick={() => setHidden(!hidden)}>
toggle
</button>
<svg height={60} width={200}>
<motion.foreignObject
id="chip"
animate={{ opacity: hidden ? 0 : 1 }}
height={40}
initial={false}
transition={
hidden
? { duration: 0.3 }
: { duration: 0.3, opacity: { duration: 0 } }
}
width={100}
x={10}
y={10}
>
<div style={{ background: "red" }}>chip</div>
</motion.foreignObject>
</svg>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
describe("waapi-svg-zero-duration", () => {
it("Restores SVG opacity with a zero-duration animation", () => {
cy.visit("?test=waapi-svg-zero-duration")
.get("#toggle")
.click()
.wait(400)
.get("#chip")
.then(([$chip]: any) => {
expect(getComputedStyle($chip).opacity).to.equal("0")
})
Comment on lines +7 to +10

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 WAAPI path remains unverified

The test checks only the final computed opacity, which the JavaScript fallback also produces. It can therefore pass without exercising the SVG WAAPI completion channel and will not reliably guard the reported native-animation regression.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

.get("#toggle")
.click()
.wait(50)
.get("#chip")
.then(([$chip]: any) => {
expect(getComputedStyle($chip).opacity).to.equal("1")
})
})
})
9 changes: 5 additions & 4 deletions packages/framer-motion/cypress/integration/waapi-svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("waapi-svg", () => {
expect(translateX).to.be.greaterThan(3)

// Per-frame rendered values remain at the initial keyframe
expect($circle.getAttribute("opacity")).to.equal("1")
expect($circle.style.opacity).to.equal("1")
expect($circle.style.transform).to.equal("translateX(0px)")
})
cy.get("#rect").then(([$rect]: any) => {
Expand All @@ -58,7 +58,7 @@ describe("waapi-svg", () => {
const [scaleX] = parseMatrix(computed.transform)
expect(scaleX).to.be.greaterThan(1.01)

expect($rect.getAttribute("opacity")).to.equal("1")
expect($rect.style.opacity).to.equal("1")
expect($rect.style.transform).to.equal("scale(1)")
})
})
Expand All @@ -74,8 +74,9 @@ describe("waapi-svg", () => {
.getAnimations()
.flatMap((animation) =>
Object.keys(
(animation.effect as KeyframeEffect).getKeyframes()[0] ??
{}
(
animation.effect as KeyframeEffect
).getKeyframes()[0] ?? {}
)
)

Expand Down
7 changes: 5 additions & 2 deletions packages/motion-dom/src/render/svg/utils/build-attrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ export function buildSVGAttrs(
const { attrs, style } = state

/**
* However, we apply transforms as CSS transforms.
* So if we detect a transform, transformOrigin we take it from attrs and copy it into style.
* However, we apply transforms and opacity as CSS styles.
*/
if (attrs.transform) {
style.transform = attrs.transform
delete attrs.transform
}
if (attrs.opacity !== undefined) {
style.opacity = attrs.opacity
delete attrs.opacity
}
if (style.transform || attrs.transformOrigin) {
style.transformOrigin = attrs.transformOrigin ?? "50% 50%"
delete attrs.transformOrigin
Expand Down