Skip to content
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

Fix AnimatePresence won't unmount fastly changing content #1569

Closed
wants to merge 9 commits into from
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from "react"
import { useId, useMemo } from "react"
import { ComponentKey } from "."
import {
PresenceContext,
PresenceContextProps,
Expand All @@ -11,11 +12,12 @@ import { PopChild } from "./PopChild"
interface PresenceChildProps {
children: React.ReactElement
isPresent: boolean
onExitComplete?: () => void
onExitComplete?: (key: ComponentKey) => void
initial?: false | VariantLabels
custom?: any
presenceAffectsLayout: boolean
mode: "sync" | "popLayout" | "wait"
childKey: ComponentKey
}

export const PresenceChild = ({
Expand All @@ -26,6 +28,7 @@ export const PresenceChild = ({
custom,
presenceAffectsLayout,
mode,
childKey,
}: PresenceChildProps) => {
const presenceChildren = useConstant(newChildrenMap)
const id = useId()
Expand All @@ -43,7 +46,7 @@ export const PresenceChild = ({
if (!isComplete) return // can stop searching when any is incomplete
}

onExitComplete?.()
onExitComplete?.(childKey)
},
register: (childId: string) => {
presenceChildren.set(childId, false)
Expand All @@ -67,7 +70,7 @@ export const PresenceChild = ({
* component immediately.
*/
React.useEffect(() => {
!isPresent && !presenceChildren.size && onExitComplete?.()
!isPresent && !presenceChildren.size && onExitComplete?.(childKey)
}, [isPresent])

if (mode === "popLayout") {
Expand Down
Loading