1
- import { ReactNode , useState } from "react"
1
+ import { lazy , ReactNode , Suspense , useState } from "react"
2
2
import type { GetStaticProps , InferGetStaticPropsType } from "next"
3
3
import { useRouter } from "next/router"
4
4
import { useTranslation } from "next-i18next"
@@ -14,25 +14,25 @@ import {
14
14
HeadingProps ,
15
15
Icon ,
16
16
SimpleGridProps ,
17
+ SkeletonText ,
17
18
Stack ,
18
19
useToken ,
19
20
} from "@chakra-ui/react"
20
21
21
22
import { AllMetricData , BasePageProps , ChildOnlyProp , Lang } from "@/lib/types"
22
- import type { CommunityEventsReturnType } from "@/lib/interfaces"
23
+ import type { CodeExample , CommunityEventsReturnType } from "@/lib/interfaces"
23
24
24
25
import ActionCard from "@/components/ActionCard"
25
26
import ButtonLink from "@/components/Buttons/ButtonLink"
26
27
import CalloutBanner from "@/components/CalloutBanner"
27
- import Codeblock from "@/components/Codeblock"
28
28
import CodeModal from "@/components/CodeModal"
29
29
import CommunityEvents from "@/components/CommunityEvents"
30
30
import HomeHero from "@/components/Hero/HomeHero"
31
31
import { Image } from "@/components/Image"
32
32
import MainArticle from "@/components/MainArticle"
33
33
import PageMetadata from "@/components/PageMetadata"
34
34
import StatsBoxGrid from "@/components/StatsBoxGrid"
35
- import TitleCardList , { ITitleCardItem } from "@/components/TitleCardList"
35
+ import TitleCardList from "@/components/TitleCardList"
36
36
import Translation from "@/components/Translation"
37
37
38
38
import { existsNamespace } from "@/lib/utils/existsNamespace"
@@ -225,6 +225,27 @@ export const getStaticProps = (async ({ locale }) => {
225
225
}
226
226
} ) satisfies GetStaticProps < Props >
227
227
228
+ const CodeblockSkeleton = ( ) => (
229
+ < Stack px = { 6 } pt = "2.75rem" h = "50vh" >
230
+ < SkeletonText
231
+ mt = "4"
232
+ noOfLines = { 6 }
233
+ spacing = { 4 }
234
+ skeletonHeight = "1.4rem"
235
+ startColor = "body.medium"
236
+ opacity = { 0.2 }
237
+ />
238
+ </ Stack >
239
+ )
240
+
241
+ const Codeblock = lazy ( ( ) =>
242
+ Promise . all ( [
243
+ import ( "@/components/Codeblock" ) ,
244
+ // Add a delay to prevent the skeleton from flashing
245
+ new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ,
246
+ ] ) . then ( ( [ module ] ) => module )
247
+ )
248
+
228
249
const HomePage = ( {
229
250
communityEvents,
230
251
metricResults,
@@ -295,11 +316,6 @@ const HomePage = ({
295
316
} ,
296
317
]
297
318
298
- interface CodeExample extends ITitleCardItem {
299
- codeLanguage : string
300
- code : string
301
- }
302
-
303
319
const codeExamples : Array < CodeExample > = [
304
320
{
305
321
title : t ( "page-index:page-index-developers-code-example-title-0" ) ,
@@ -538,19 +554,24 @@ const HomePage = ({
538
554
</ ButtonLink >
539
555
</ ButtonLinkRow >
540
556
</ FeatureContent >
541
- < CodeModal
542
- isOpen = { isModalOpen }
543
- setIsOpen = { setModalOpen }
544
- title = { codeExamples [ activeCode ] . title }
545
- >
546
- < Codeblock
547
- codeLanguage = { codeExamples [ activeCode ] . codeLanguage }
548
- allowCollapse = { false }
549
- fromHomepage
557
+ { /* Render CodeModal & Codeblock conditionally */ }
558
+ { isModalOpen && (
559
+ < CodeModal
560
+ isOpen = { isModalOpen }
561
+ setIsOpen = { setModalOpen }
562
+ title = { codeExamples [ activeCode ] . title }
550
563
>
551
- { codeExamples [ activeCode ] . code }
552
- </ Codeblock >
553
- </ CodeModal >
564
+ < Suspense fallback = { < CodeblockSkeleton /> } >
565
+ < Codeblock
566
+ codeLanguage = { codeExamples [ activeCode ] . codeLanguage }
567
+ allowCollapse = { false }
568
+ fromHomepage
569
+ >
570
+ { codeExamples [ activeCode ] . code }
571
+ </ Codeblock >
572
+ </ Suspense >
573
+ </ CodeModal >
574
+ ) }
554
575
</ Row >
555
576
</ MainSectionContainer >
556
577
{ /* Eth Today Section */ }
0 commit comments