Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Motion adheres to [Semantic Versioning](http://semver.org/).

Undocumented APIs should be considered internal and may change without warning.

## [Unreleased]

### Fixed

- `AnimatePresence`: Fix object-form `initial` values not applied on re-entry after exit completes.

## [12.38.0] 2026-03-16

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,72 @@ describe("AnimatePresence with custom components", () => {
expect(enterCustomValues).toContain(1)
})

test("Re-entering child with object-form initial resets to initial values when exit was complete", async () => {
const opacity = motionValue(1)
const opacityChanges: number[] = []

opacity.on("change", (v) => {
opacityChanges.push(v)
})

const Component = ({
showA,
showB,
}: {
showA: boolean
showB: boolean
}) => {
return (
<AnimatePresence>
{showA && (
<motion.div
key="a"
initial={{ x: 0 }}
animate={{ x: 100 }}
exit={{ x: -100 }}
transition={{ duration: 10 }}
/>
)}
{showB && (
<motion.div
key="b"
initial={{ opacity: 0.5 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
style={{ opacity }}
transition={{ type: false }}
/>
)}
</AnimatePresence>
)
}

const { rerender } = render(<Component showA showB />)
await act(async () => {
await nextFrame()
})

await act(async () => {
rerender(<Component showA={false} showB={false} />)
})
await act(async () => {
await nextFrame()
})

expect(opacity.get()).toBe(0)

opacityChanges.length = 0
await act(async () => {
rerender(<Component showA={false} showB />)
})
await act(async () => {
await nextFrame()
})

expect(opacityChanges.length).toBeGreaterThan(0)
expect(opacityChanges[0]).toBe(0.5)
})

test("Does not get stuck when state changes cause rapid key alternation in mode='wait'", async () => {
/**
* Reproduction from #3141: A loading/loaded pattern where
Expand Down
7 changes: 6 additions & 1 deletion packages/framer-motion/src/motion/features/animation/exit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ export class ExitAnimationFeature extends Feature<unknown> {
if (this.isExitComplete) {
const { initial, custom } = this.node.getProps()

if (typeof initial === "string") {
if (
typeof initial === "string" ||
(typeof initial === "object" &&
initial !== null &&
!Array.isArray(initial))
) {
const resolved = resolveVariant(
this.node,
initial,
Expand Down