From 18fa93365cceb0fbb93e89db6c2363b7725fa065 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 6 Aug 2021 03:25:21 +0300 Subject: [PATCH] Transition: Fix exception when missing node --- src/components/ui/Transition.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/ui/Transition.tsx b/src/components/ui/Transition.tsx index 1d3265888..509050aec 100644 --- a/src/components/ui/Transition.tsx +++ b/src/components/ui/Transition.tsx @@ -140,6 +140,10 @@ const Transition: FC = ({ requestAnimationFrame(() => { container.classList.add('animating'); + if (onStart) { + onStart(); + } + function onAnimationEnd() { requestAnimationFrame(() => { container.classList.remove('animating', 'backwards'); @@ -172,16 +176,15 @@ const Transition: FC = ({ }); } - if (animationLevel > 0) { - const toNode = name === 'mv-slide' ? childNodes[activeIndex].firstChild! : childNodes[activeIndex]; + const toNode = name === 'mv-slide' + ? childNodes[activeIndex] && childNodes[activeIndex].firstChild + : childNodes[activeIndex]; + + if (animationLevel > 0 && toNode) { waitForAnimationEnd(toNode, onAnimationEnd); } else { onAnimationEnd(); } - - if (onStart) { - onStart(); - } }); }, [ activeKey,