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) <noreply@anthropic.com>
This commit is contained in:
+13
-2
@@ -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<FavoriteListing[]>(favoriteListings);
|
||||
const [favoritesPreferredTab, setFavoritesPreferredTab] = useState<FavoriteTab>('buy');
|
||||
const [listingPriceAlertSubscriptionsState, setListingPriceAlertSubscriptionsState] = useState<ListingPriceAlertSubscription[]>([]);
|
||||
@@ -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 (
|
||||
<div className={`site-shell ${location.pathname === ROUTES.login ? 'login-shell' : ''}`}>
|
||||
<Header onLogout={handleLogout} hasUnreadFavorites={unreadFavoriteIds.size > 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user