From c815ac29ea281056908f39dfb6a390b3b201377b Mon Sep 17 00:00:00 2001 From: c0mrade Date: Mon, 2 Feb 2026 07:02:50 +0300 Subject: [PATCH] fix: scroll to start of tariffs section and wait for data to load --- src/pages/Subscription.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pages/Subscription.tsx b/src/pages/Subscription.tsx index 402de39..0baf7c9 100644 --- a/src/pages/Subscription.tsx +++ b/src/pages/Subscription.tsx @@ -519,15 +519,16 @@ export default function Subscription() { // Auto-scroll to tariffs section when coming from Dashboard "Продлить" button useEffect(() => { const state = location.state as { scrollToExtend?: boolean } | null; - if (state?.scrollToExtend && tariffsCardRef.current) { + // Wait for tariffs to load before scrolling + if (state?.scrollToExtend && tariffsCardRef.current && tariffs.length > 0) { const timer = setTimeout(() => { - tariffsCardRef.current?.scrollIntoView({ behavior: 'smooth', block: 'center' }); - }, 300); + tariffsCardRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' }); + }, 100); // Clear the state to prevent re-scrolling on subsequent renders window.history.replaceState({}, document.title); return () => clearTimeout(timer); } - }, [location.state]); + }, [location.state, tariffs.length]); const copyUrl = () => { if (subscription?.subscription_url) {