larxius commited on
Commit
6879a9a
·
verified ·
1 Parent(s): 7fd3b33

Update frontend/src/components/Layout.jsx

Browse files
Files changed (1) hide show
  1. frontend/src/components/Layout.jsx +5 -30
frontend/src/components/Layout.jsx CHANGED
@@ -49,37 +49,12 @@ export const Layout = ({ children }) => {
49
  setGlobalSearchQuery(urlQuery);
50
  }, [urlQuery]);
51
 
52
- // Restore and persist scroll position across page refresh
53
  useEffect(() => {
54
- try {
55
- const scrollKey = `scroll_pos_${location.pathname}${location.search}`;
56
- const savedScroll = sessionStorage.getItem(scrollKey);
57
- if (savedScroll) {
58
- const scrollY = parseInt(savedScroll, 10);
59
- if (!isNaN(scrollY) && scrollY > 0) {
60
- const timer = setTimeout(() => {
61
- try {
62
- window.scrollTo(0, scrollY);
63
- } catch (e) {}
64
- }, 80);
65
- return () => clearTimeout(timer);
66
- }
67
- }
68
- } catch (e) {}
69
- }, [location.pathname, location.search]);
70
-
71
- useEffect(() => {
72
- const handleScroll = () => {
73
- try {
74
- const scrollKey = `scroll_pos_${location.pathname}${location.search}`;
75
- sessionStorage.setItem(scrollKey, window.scrollY.toString());
76
- } catch (e) {}
77
- };
78
- window.addEventListener('scroll', handleScroll, { passive: true });
79
- return () => {
80
- window.removeEventListener('scroll', handleScroll);
81
- };
82
- }, [location.pathname, location.search]);
83
 
84
  const [isDemoMode, setIsDemoMode] = useState(false);
85
  const [isProfileOpen, setIsProfileOpen] = useState(false);
 
49
  setGlobalSearchQuery(urlQuery);
50
  }, [urlQuery]);
51
 
52
+ // Always scroll to top of page on route change
53
  useEffect(() => {
54
+ window.scrollTo(0, 0);
55
+ const mainElement = document.querySelector('main');
56
+ if (mainElement) mainElement.scrollTop = 0;
57
+ }, [location.pathname]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
  const [isDemoMode, setIsDemoMode] = useState(false);
60
  const [isProfileOpen, setIsProfileOpen] = useState(false);