From 5f5bec72322f01dc177e2c56c05987d8e1bcfe47 Mon Sep 17 00:00:00 2001 From: pascal Date: Thu, 23 Jul 2026 23:48:43 +0200 Subject: [PATCH] Przewijanie przy zmianie trasy i naprawa petli renderow w porownaniu ofert - nowa trasa startuje od gory strony, przy cofaniu (POP) pozycja zostaje przy przegladarce, wiec powrot do listy ofert wraca w to samo miejsce - AccountComparisonPage: setSelectedDetails({}) tworzylo nowy obiekt przy kazdym przebiegu efektu zaleznego od selectedDetails, co dawalo nieskonczona petle ("Maximum update depth exceeded"). Blad byl obecny przed migracja - ujawnily go testy E2E nowej trasy /konto/porownanie. Co-Authored-By: Claude Opus 4.8 (1M context) --- frontend/src/App.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 8867836..8586684 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,6 +1,6 @@ import { Fragment, type ChangeEvent as ReactChangeEvent, type ClipboardEvent as ReactClipboardEvent, type Dispatch, type DragEvent as ReactDragEvent, type FormEvent as ReactFormEvent, type KeyboardEvent as ReactKeyboardEvent, type MouseEvent as ReactMouseEvent, type PointerEvent as ReactPointerEvent, type ReactNode, type SetStateAction, type WheelEvent as ReactWheelEvent, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'; import './styles.css'; -import { Link, NavLink, Navigate, Outlet, Route, Routes, useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom'; +import { Link, NavLink, Route, Routes, useLocation, useNavigate, useNavigationType, useParams, useSearchParams } from 'react-router-dom'; import { ROUTES, listingPath, mapPath, negotiationPath, adminTabPath, ADMIN_PATH_TO_TAB, type AdminTabKey } from './routes'; import { ProtectedRoute } from './ProtectedRoute'; import { apiFetch, useAuth } from './auth'; @@ -2619,6 +2619,7 @@ function App() { const { user, logout } = useAuth(); const navigate = useNavigate(); const location = useLocation(); + const navigationType = useNavigationType(); const [favoriteListingsState, setFavoriteListingsState] = useState(favoriteListings); const [favoritesPreferredTab, setFavoritesPreferredTab] = useState('buy'); const [listingPriceAlertSubscriptionsState, setListingPriceAlertSubscriptionsState] = useState([]); @@ -3365,6 +3366,14 @@ function App() { }; }, [user, monitoredListingIdList, monitoredListingIdsSignature, listingPriceAlertIdList, listingPriceAlertIdsSignature]); + // Wejscie na nowa trase zaczynamy od gory strony. Przy cofaniu (POP) zostawiamy + // pozycje przegladarce, zeby powrot do listy ofert wracal w to samo miejsce. + useEffect(() => { + if (navigationType !== 'POP') { + window.scrollTo({ top: 0, behavior: 'auto' }); + } + }, [location.pathname, navigationType]); + return (
0} onOpenNotification={handleOpenNotification} /> @@ -6897,7 +6906,9 @@ function AccountComparisonPage({ onOpenListing }: { onOpenListing: (id: number) useEffect(() => { if (selectedIds.length === 0) { - setSelectedDetails({}); + // Zachowujemy referencje pustego obiektu - podstawienie nowego {} zmienialoby + // zaleznosc selectedDetails i efekt wpadalby w nieskonczona petle renderow. + setSelectedDetails((current) => (Object.keys(current).length === 0 ? current : {})); return; }