Skip to content

Commit 3994079

Browse files
committed
claude:chore: 1. Lazy-loaded route pages — All page imports except Home converted to React.lazy() with Suspense, cutting the main bundle from 1,371KB to 629KB
2. Smooth scroll-to-top fix — Moved ScrollToTop out of root layout into a Lazy wrapper component (src/route/lazy.jsx) so the scroll triggers after the lazy page renders, not before 3. HMR fix — Extracted Lazy/ScrollOnMount into a separate file to avoid the Fast Refresh incompatibility warning 4. Reward claims key fix — Added index tiebreaker to the React key to handle duplicate transaction-recipient pairs
1 parent dca053b commit 3994079

4 files changed

Lines changed: 40 additions & 22 deletions

File tree

src/components/ui/rewardClaims.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const RewardClaims = ({ data, isLoading, error }: {
7979
const symbol = C.CHAIN_SYMBOL[reward.chain]
8080
const txUrl = chainToTransactionUrl(reward.chain, reward.protocol, reward.transaction)
8181
const addrUrl = chainToAddressUrl(reward.chain, reward.protocol, reward.recipient)
82-
return <div className="reward-claim-card" key={`${reward.transaction}-${reward.recipient}`}>
82+
return <div className="reward-claim-card" key={`${reward.transaction}-${reward.recipient}-${i}`}>
8383
<div className="reward-claim-card-top">
8484
<img src={logo} width={28} alt={symbol} />
8585
<span className="reward-claim-protocol">{C.PROTOCOL_NAME[reward.protocol]}</span>

src/layout/root.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import Footer from '../components/sections/footer'
99
import CallToAction from '../components/sections/callToAction'
1010
import Preloader from '../components/ui/preloader'
1111
import DiscoverWalletProviders from '../components/sections/eip6963'
12-
import ScrollToTop from '../components/sections/scrollToTop'
1312
import { Tooltip } from 'react-tooltip'
1413
import { useEffect } from 'react'
1514
import { CookiesProvider } from 'react-cookie'
@@ -63,7 +62,6 @@ const RootLayout = () => {
6362
<ToastContainer theme='dark' position='top-left' />
6463
<Tooltip id="tooltip" />
6564
<DiscoverWalletProviders />
66-
<ScrollToTop />
6765
</>
6866
)
6967
}

src/route/lazy.jsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Suspense, useEffect } from "react";
2+
import { useLocation } from "react-router-dom";
3+
4+
const ScrollOnMount = () => {
5+
const { pathname } = useLocation();
6+
useEffect(() => {
7+
requestAnimationFrame(() => {
8+
window.scrollTo({ top: 0, behavior: "smooth" });
9+
});
10+
}, [pathname]);
11+
return null;
12+
};
13+
14+
const Lazy = ({ children }) => (
15+
<Suspense fallback={null}>
16+
{children}
17+
<ScrollOnMount />
18+
</Suspense>
19+
);
20+
21+
export default Lazy;

src/route/router.jsx

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
import { lazy } from "react";
12
import { createHashRouter } from "react-router-dom";
23
import RootLayout from "../layout/root";
34
import Home from "../pages/home";
4-
import Contact from "../pages/contact";
5-
import About from "../pages/about";
6-
import AvalancheValidatorProject from "../pages/protocols/avalanche-validator/page";
7-
import FlareValidatorProject from "../pages/protocols/flare-validator/page";
8-
import FlareFspProject from "../pages/protocols/flare-fsp/page";
9-
import SongbirdFspProject from "../pages/protocols/songbird-fsp/page";
10-
import Protocols from "../pages/protocols";
5+
import Lazy from "./lazy";
6+
7+
const Contact = lazy(() => import("../pages/contact"));
8+
const About = lazy(() => import("../pages/about"));
9+
const Protocols = lazy(() => import("../pages/protocols"));
10+
const AvalancheValidatorProject = lazy(() => import("../pages/protocols/avalanche-validator/page"));
11+
const FlareValidatorProject = lazy(() => import("../pages/protocols/flare-validator/page"));
12+
const FlareFspProject = lazy(() => import("../pages/protocols/flare-fsp/page"));
13+
const SongbirdFspProject = lazy(() => import("../pages/protocols/songbird-fsp/page"));
1114

1215

1316
export const router = createHashRouter([
@@ -21,36 +24,32 @@ export const router = createHashRouter([
2124
},
2225
{
2326
path: "/contact",
24-
element: <Contact />
27+
element: <Lazy><Contact /></Lazy>
2528
},
2629
{
2730
path: "/about",
28-
element: <About />
31+
element: <Lazy><About /></Lazy>
2932
},
30-
/* {
31-
path: "/service",
32-
element: <Service />
33-
}, */
3433
{
3534
path: "/protocols",
36-
element: <Protocols />
35+
element: <Lazy><Protocols /></Lazy>
3736
},
3837
{
3938
path: "/avalanche/validator",
40-
element: <AvalancheValidatorProject />
39+
element: <Lazy><AvalancheValidatorProject /></Lazy>
4140
},
4241
{
4342
path: "/flare/validator",
44-
element: <FlareValidatorProject />
43+
element: <Lazy><FlareValidatorProject /></Lazy>
4544
},
4645
{
4746
path: "/flare/fsp",
48-
element: <FlareFspProject />
47+
element: <Lazy><FlareFspProject /></Lazy>
4948
},
5049
{
5150
path: "/songbird/fsp",
52-
element: <SongbirdFspProject />
51+
element: <Lazy><SongbirdFspProject /></Lazy>
5352
}
5453
]
5554
}
56-
])
55+
])

0 commit comments

Comments
 (0)