Merged in fix/modal-fast-close (pull request #2100)

fix - use animateprecence to avoid page freeze

* fix - use animateprecence to avoid page freeze


Approved-by: Michael Zetterberg
This commit is contained in:
Linus Flood
2025-05-15 05:13:17 +00:00
parent d0a3d0c228
commit 1c70047ae8

View File

@@ -1,7 +1,7 @@
"use client" "use client"
import { cx } from "class-variance-authority" import { cx } from "class-variance-authority"
import { motion } from "framer-motion" import { AnimatePresence, motion } from "framer-motion"
import { type PropsWithChildren, useEffect, useState } from "react" import { type PropsWithChildren, useEffect, useState } from "react"
import { import {
Dialog, Dialog,
@@ -154,8 +154,12 @@ export default function Modal({
} }
}, [isOpen]) }, [isOpen])
const shouldRender = isOpen || animation !== AnimationStateEnum.unmounted
if (!trigger) { if (!trigger) {
return ( return (
<AnimatePresence>
{shouldRender && (
<InnerModal <InnerModal
onAnimationComplete={onAnimationComplete} onAnimationComplete={onAnimationComplete}
animation={animation} animation={animation}
@@ -170,6 +174,8 @@ export default function Modal({
> >
{children} {children}
</InnerModal> </InnerModal>
)}
</AnimatePresence>
) )
} }
@@ -182,6 +188,8 @@ export default function Modal({
} }
> >
{trigger} {trigger}
<AnimatePresence>
{shouldRender && (
<InnerModal <InnerModal
onAnimationComplete={onAnimationComplete} onAnimationComplete={onAnimationComplete}
animation={animation} animation={animation}
@@ -193,6 +201,8 @@ export default function Modal({
> >
{children} {children}
</InnerModal> </InnerModal>
)}
</AnimatePresence>
</DialogTrigger> </DialogTrigger>
) )
} }