Skip to content

Commit f7f622a

Browse files
committed
fix: lighten library landing page startup
1 parent cefa9eb commit f7f622a

File tree

7 files changed

+67
-49
lines changed

7 files changed

+67
-49
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react'
2+
import type { Framework } from '~/libraries'
3+
import { useIntersectionObserver } from '~/hooks/useIntersectionObserver'
4+
5+
const LazyCodeExampleCardImpl = React.lazy(async () => {
6+
const mod = await import('./CodeExampleCard')
7+
8+
return { default: mod.CodeExampleCard }
9+
})
10+
11+
interface LazyCodeExampleCardProps {
12+
title?: string
13+
frameworks: Framework[]
14+
codeByFramework: Partial<Record<Framework, { lang: string; code: string }>>
15+
}
16+
17+
export function LazyCodeExampleCard(props: LazyCodeExampleCardProps) {
18+
const { ref, isIntersecting } = useIntersectionObserver({
19+
rootMargin: '25%',
20+
triggerOnce: true,
21+
})
22+
23+
return (
24+
<div ref={ref} className="px-4 space-y-4 flex flex-col items-center">
25+
{!isIntersecting ? (
26+
<div className="w-full max-w-5xl mx-auto space-y-4">
27+
<div className="h-10 w-56 mx-auto rounded bg-gray-200/70 dark:bg-gray-800/70 animate-pulse" />
28+
<div className="rounded-xl border border-gray-200 dark:border-gray-800 bg-white/70 dark:bg-gray-900/70 overflow-hidden">
29+
<div className="h-14 border-b border-gray-200 dark:border-gray-800 bg-gray-100/70 dark:bg-gray-800/70 animate-pulse" />
30+
<div className="p-4 space-y-3">
31+
<div className="h-4 w-11/12 rounded bg-gray-200/70 dark:bg-gray-800/70 animate-pulse" />
32+
<div className="h-4 w-10/12 rounded bg-gray-200/70 dark:bg-gray-800/70 animate-pulse" />
33+
<div className="h-4 w-8/12 rounded bg-gray-200/70 dark:bg-gray-800/70 animate-pulse" />
34+
<div className="h-4 w-9/12 rounded bg-gray-200/70 dark:bg-gray-800/70 animate-pulse" />
35+
<div className="h-4 w-7/12 rounded bg-gray-200/70 dark:bg-gray-800/70 animate-pulse" />
36+
<div className="h-48 rounded bg-gray-100/70 dark:bg-gray-800/50 animate-pulse" />
37+
</div>
38+
</div>
39+
</div>
40+
) : (
41+
<React.Suspense fallback={null}>
42+
<LazyCodeExampleCardImpl {...props} />
43+
</React.Suspense>
44+
)}
45+
</div>
46+
)
47+
}

src/components/landing/FormLanding.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { LibraryTestimonials } from '~/components/LibraryTestimonials'
1414
import { LibraryShowcases } from '~/components/ShowcaseSection'
1515
import { LibraryPageContainer } from '~/components/LibraryPageContainer'
1616
import { LibraryStatsSection } from '~/components/LibraryStatsSection'
17-
import { CodeExampleCard } from '~/components/CodeExampleCard'
17+
import { LazyCodeExampleCard } from '~/components/LazyCodeExampleCard'
1818
import { StackBlitzSection } from '~/components/StackBlitzSection'
1919

2020
const library = getLibrary('form')
@@ -148,7 +148,7 @@ export default function FormLanding() {
148148

149149
<LibraryTestimonials testimonials={formProject.testimonials} />
150150

151-
<CodeExampleCard
151+
<LazyCodeExampleCard
152152
frameworks={formProject.frameworks}
153153
codeByFramework={codeExamples}
154154
/>

src/components/landing/QueryLanding.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { LibraryTestimonials } from '~/components/LibraryTestimonials'
1414
import { LibraryShowcases } from '~/components/ShowcaseSection'
1515
import { LibraryPageContainer } from '~/components/LibraryPageContainer'
1616
import { LibraryStatsSection } from '~/components/LibraryStatsSection'
17-
import { CodeExampleCard } from '~/components/CodeExampleCard'
17+
import { LazyCodeExampleCard } from '~/components/LazyCodeExampleCard'
1818
import { StackBlitzSection } from '~/components/StackBlitzSection'
1919
import { FeatureGridSection } from '~/components/FeatureGridSection'
2020

@@ -163,7 +163,7 @@ export default function QueryLanding() {
163163

164164
<LibraryStatsSection library={library} />
165165

166-
<CodeExampleCard
166+
<LazyCodeExampleCard
167167
frameworks={queryProject.frameworks}
168168
codeByFramework={codeExamples}
169169
/>

src/components/landing/RouterLanding.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { LibraryTestimonials } from '~/components/LibraryTestimonials'
1414
import { LibraryShowcases } from '~/components/ShowcaseSection'
1515
import { LibraryPageContainer } from '~/components/LibraryPageContainer'
1616
import { LibraryStatsSection } from '~/components/LibraryStatsSection'
17-
import { CodeExampleCard } from '~/components/CodeExampleCard'
17+
import { LazyCodeExampleCard } from '~/components/LazyCodeExampleCard'
1818
import { StackBlitzSection } from '~/components/StackBlitzSection'
1919

2020
const library = getLibrary('router')
@@ -78,7 +78,7 @@ export default function RouterLanding() {
7878

7979
<LibraryStatsSection library={library} />
8080

81-
<CodeExampleCard
81+
<LazyCodeExampleCard
8282
frameworks={routerProject.frameworks}
8383
codeByFramework={codeExamples}
8484
/>

src/components/landing/VirtualLanding.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { MaintainersSection } from '~/components/MaintainersSection'
1717
import { LibraryTestimonials } from '~/components/LibraryTestimonials'
1818
import { LibraryPageContainer } from '~/components/LibraryPageContainer'
1919
import { LibraryStatsSection } from '~/components/LibraryStatsSection'
20-
import { CodeExampleCard } from '~/components/CodeExampleCard'
20+
import { LazyCodeExampleCard } from '~/components/LazyCodeExampleCard'
2121

2222
const library = getLibrary('virtual')
2323

@@ -146,7 +146,7 @@ export default function VirtualLanding() {
146146

147147
<LibraryStatsSection library={library} />
148148

149-
<CodeExampleCard
149+
<LazyCodeExampleCard
150150
frameworks={virtualProject.frameworks}
151151
codeByFramework={codeExamples}
152152
/>
Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import {
2-
useMatch,
3-
Link,
4-
notFound,
5-
createFileRoute,
6-
} from '@tanstack/react-router'
7-
import { DocsLayout } from '~/components/DocsLayout'
1+
import { Link, notFound, createFileRoute } from '@tanstack/react-router'
82
import { findLibrary } from '~/libraries'
93
import type { LibraryId } from '~/libraries'
104
import { seo } from '~/utils/seo'
115

126
import { Button } from '~/ui'
13-
import { ConfigSchema } from '~/utils/config'
147
import { landingComponents } from './$version'
158

169
export const Route = createFileRoute('/$libraryId/$version/')({
@@ -41,26 +34,13 @@ function LibraryVersionIndex() {
4134
if (!library) {
4235
throw notFound()
4336
}
44-
const versionMatch = useMatch({ from: '/$libraryId/$version' })
45-
const { config } = versionMatch.loaderData as { config: ConfigSchema }
4637

4738
const LandingComponent = landingComponents[libraryId as LibraryId]
4839

4940
if (!LandingComponent) {
5041
return (
51-
<DocsLayout
52-
name={library.name.replace('TanStack ', '')}
53-
version={version === 'latest' ? library.latestVersion : version!}
54-
colorFrom={library.accentColorFrom ?? library.colorFrom}
55-
colorTo={library.accentColorTo ?? library.colorTo}
56-
textColor={library.accentTextColor ?? library.textColor ?? ''}
57-
config={config}
58-
frameworks={library.frameworks}
59-
versions={library.availableVersions}
60-
repo={library.repo}
61-
isLandingPage
62-
>
63-
<div className="flex flex-col items-center justify-center min-h-[50vh] gap-4">
42+
<div className="px-4 pt-32 pb-24">
43+
<div className="flex flex-col items-center justify-center min-h-[50vh] gap-4 max-w-3xl mx-auto text-center">
6444
<h1 className="text-2xl font-bold">{library.name}</h1>
6545
<p className="text-gray-600">{library.description}</p>
6646
<Button
@@ -71,24 +51,9 @@ function LibraryVersionIndex() {
7151
View Documentation
7252
</Button>
7353
</div>
74-
</DocsLayout>
54+
</div>
7555
)
7656
}
7757

78-
return (
79-
<DocsLayout
80-
name={library.name.replace('TanStack ', '')}
81-
version={version === 'latest' ? library.latestVersion : version!}
82-
colorFrom={library.accentColorFrom ?? library.colorFrom}
83-
colorTo={library.accentColorTo ?? library.colorTo}
84-
textColor={library.accentTextColor ?? library.textColor ?? ''}
85-
config={config}
86-
frameworks={library.frameworks}
87-
versions={library.availableVersions}
88-
repo={library.repo}
89-
isLandingPage
90-
>
91-
<LandingComponent />
92-
</DocsLayout>
93-
)
58+
return <LandingComponent />
9459
}

src/routes/$libraryId/$version.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,15 @@ export const Route = createFileRoute('/$libraryId/$version')({
6464
})
6565
}
6666

67-
await landingComponents[libraryId as LibraryId]?.preload?.()
67+
if (!ctx.location.pathname.includes('/docs')) {
68+
await landingComponents[libraryId as LibraryId]?.preload?.()
69+
}
6870
},
6971
loader: async (ctx) => {
72+
if (!ctx.location.pathname.includes('/docs')) {
73+
return { config: null }
74+
}
75+
7076
const { libraryId, version } = ctx.params
7177
const library = findLibrary(libraryId)
7278

0 commit comments

Comments
 (0)