From 1c70047ae8a8b95bb53bb01e844e0a7a5aab8c77 Mon Sep 17 00:00:00 2001 From: Linus Flood Date: Thu, 15 May 2025 05:13:17 +0000 Subject: [PATCH] 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 --- apps/scandic-web/components/Modal/index.tsx | 62 ++++++++++++--------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/apps/scandic-web/components/Modal/index.tsx b/apps/scandic-web/components/Modal/index.tsx index cd4a9be32..ca25338fd 100644 --- a/apps/scandic-web/components/Modal/index.tsx +++ b/apps/scandic-web/components/Modal/index.tsx @@ -1,7 +1,7 @@ "use client" 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 { Dialog, @@ -154,22 +154,28 @@ export default function Modal({ } }, [isOpen]) + const shouldRender = isOpen || animation !== AnimationStateEnum.unmounted + if (!trigger) { return ( - - {children} - + + {shouldRender && ( + + {children} + + )} + ) } @@ -182,17 +188,21 @@ export default function Modal({ } > {trigger} - - {children} - + + {shouldRender && ( + + {children} + + )} + ) }