From 6249982d821306b2bece320ff12aacc862b38871 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Tue, 7 May 2024 05:57:21 +1000 Subject: [PATCH] fix(ui): stuck viewer when spamming toggle There are a number of bugs with `framer-motion` that can result in sync issues with AnimatePresence and the conditionally rendered component. You can see this if you rapidly click an accordion, occasionally it gets out of sync and is closed when it should be open. This is a bigger problem with the viewer where the user may hold down the `z` key. It's trivial to get it to lock up. For now, just remove the animation entirely. Upstream issues for reference: https://github.com/framer/motion/issues/2023 https://github.com/framer/motion/issues/2618 https://github.com/framer/motion/issues/2554 --- .../components/ImageViewer/ImageViewer.tsx | 90 ++++++++----------- 1 file changed, 35 insertions(+), 55 deletions(-) diff --git a/invokeai/frontend/web/src/features/gallery/components/ImageViewer/ImageViewer.tsx b/invokeai/frontend/web/src/features/gallery/components/ImageViewer/ImageViewer.tsx index 949e72fad1..dcd4d4c304 100644 --- a/invokeai/frontend/web/src/features/gallery/components/ImageViewer/ImageViewer.tsx +++ b/invokeai/frontend/web/src/features/gallery/components/ImageViewer/ImageViewer.tsx @@ -5,8 +5,6 @@ import { ToggleProgressButton } from 'features/gallery/components/ImageViewer/To import { useImageViewer } from 'features/gallery/components/ImageViewer/useImageViewer'; import type { InvokeTabName } from 'features/ui/store/tabMap'; import { activeTabNameSelector } from 'features/ui/store/uiSelectors'; -import type { AnimationProps } from 'framer-motion'; -import { AnimatePresence, motion } from 'framer-motion'; import { memo, useMemo } from 'react'; import { useHotkeys } from 'react-hotkeys-hook'; @@ -14,18 +12,6 @@ import CurrentImageButtons from './CurrentImageButtons'; import CurrentImagePreview from './CurrentImagePreview'; import { EditorButton } from './EditorButton'; -const initial: AnimationProps['initial'] = { - opacity: 0, -}; -const animate: AnimationProps['animate'] = { - opacity: 1, - transition: { duration: 0.07 }, -}; -const exit: AnimationProps['exit'] = { - opacity: 0, - transition: { duration: 0.07 }, -}; - const VIEWER_ENABLED_TABS: InvokeTabName[] = ['canvas', 'generation', 'workflows']; export const ImageViewer = memo(() => { @@ -42,50 +28,44 @@ export const ImageViewer = memo(() => { useHotkeys('z', onToggle, { enabled: isViewerEnabled }, [isViewerEnabled, onToggle]); useHotkeys('esc', onClose, { enabled: isViewerEnabled }, [isViewerEnabled, onClose]); - // The AnimatePresence mode must be wait - else framer can get confused if you spam the toggle button + if (!shouldShowViewer) { + return null; + } + return ( - - {shouldShowViewer && ( - - - - - - - - - - - - - - - - + + + + + + - - )} - + + + + + + + + + + + ); });