larxius commited on
Commit
803c09b
·
verified ·
1 Parent(s): 720da9a

Update frontend/src/components/Layout.jsx

Browse files
Files changed (1) hide show
  1. frontend/src/components/Layout.jsx +18 -12
frontend/src/components/Layout.jsx CHANGED
@@ -17,23 +17,29 @@ export const Layout = ({ children }) => {
17
 
18
  // Restore and persist scroll position across page refresh
19
  useEffect(() => {
20
- const scrollKey = `scroll_pos_${location.pathname}${location.search}`;
21
- const savedScroll = sessionStorage.getItem(scrollKey);
22
- if (savedScroll) {
23
- const scrollY = parseInt(savedScroll, 10);
24
- if (!isNaN(scrollY) && scrollY > 0) {
25
- const timer = setTimeout(() => {
26
- window.scrollTo({ top: scrollY, behavior: 'instant' });
27
- }, 80);
28
- return () => clearTimeout(timer);
 
 
 
 
29
  }
30
- }
31
  }, [location.pathname, location.search]);
32
 
33
  useEffect(() => {
34
  const handleScroll = () => {
35
- const scrollKey = `scroll_pos_${location.pathname}${location.search}`;
36
- sessionStorage.setItem(scrollKey, window.scrollY.toString());
 
 
37
  };
38
  window.addEventListener('scroll', handleScroll, { passive: true });
39
  return () => {
 
17
 
18
  // Restore and persist scroll position across page refresh
19
  useEffect(() => {
20
+ try {
21
+ const scrollKey = `scroll_pos_${location.pathname}${location.search}`;
22
+ const savedScroll = sessionStorage.getItem(scrollKey);
23
+ if (savedScroll) {
24
+ const scrollY = parseInt(savedScroll, 10);
25
+ if (!isNaN(scrollY) && scrollY > 0) {
26
+ const timer = setTimeout(() => {
27
+ try {
28
+ window.scrollTo(0, scrollY);
29
+ } catch (e) {}
30
+ }, 80);
31
+ return () => clearTimeout(timer);
32
+ }
33
  }
34
+ } catch (e) {}
35
  }, [location.pathname, location.search]);
36
 
37
  useEffect(() => {
38
  const handleScroll = () => {
39
+ try {
40
+ const scrollKey = `scroll_pos_${location.pathname}${location.search}`;
41
+ sessionStorage.setItem(scrollKey, window.scrollY.toString());
42
+ } catch (e) {}
43
  };
44
  window.addEventListener('scroll', handleScroll, { passive: true });
45
  return () => {