Skip to content

Commit 777ce0e

Browse files
committed
improve lib landing
1 parent bb97bc6 commit 777ce0e

7 files changed

Lines changed: 77 additions & 41 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { useQuery } from '@tanstack/react-query'
2+
import type { LibraryId } from '~/libraries'
3+
import { useIntersectionObserver } from '~/hooks/useIntersectionObserver'
4+
import { fetchLandingCodeExample } from '~/utils/landing-code-example.functions'
5+
6+
function LandingCodeExamplePlaceholder() {
7+
return (
8+
<div className="px-4 space-y-4 flex flex-col items-center">
9+
<div className="text-3xl font-black">Just a quick look...</div>
10+
<div className="w-full max-w-3xl min-w-0 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 animate-pulse">
11+
<div className="flex gap-2 border-b border-gray-200 dark:border-gray-700 px-3 py-2">
12+
<div className="h-6 w-16 rounded bg-gray-200 dark:bg-gray-700" />
13+
<div className="h-6 w-16 rounded bg-gray-200 dark:bg-gray-700" />
14+
<div className="h-6 w-16 rounded bg-gray-200 dark:bg-gray-700" />
15+
</div>
16+
<div className="space-y-3 p-4">
17+
<div className="h-4 w-5/6 rounded bg-gray-200 dark:bg-gray-700" />
18+
<div className="h-4 w-3/4 rounded bg-gray-200 dark:bg-gray-700" />
19+
<div className="h-4 w-4/5 rounded bg-gray-200 dark:bg-gray-700" />
20+
<div className="h-4 w-2/3 rounded bg-gray-200 dark:bg-gray-700" />
21+
</div>
22+
</div>
23+
</div>
24+
)
25+
}
26+
27+
export function LazyLandingCodeExample({
28+
libraryId,
29+
}: {
30+
libraryId: LibraryId
31+
}) {
32+
const { ref, isIntersecting } = useIntersectionObserver({
33+
rootMargin: '25%',
34+
triggerOnce: true,
35+
})
36+
const { data, isLoading } = useQuery({
37+
queryKey: ['landing-code-example', libraryId],
38+
queryFn: () =>
39+
fetchLandingCodeExample({
40+
data: {
41+
libraryId,
42+
},
43+
}),
44+
enabled: isIntersecting,
45+
staleTime: 5 * 60 * 1000,
46+
})
47+
48+
if (isIntersecting && !isLoading && !data?.contentRsc) {
49+
return null
50+
}
51+
52+
return (
53+
<div ref={ref}>
54+
{data?.contentRsc ? data.contentRsc : <LandingCodeExamplePlaceholder />}
55+
</div>
56+
)
57+
}

src/components/landing/FormLanding.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ import { LibraryHero } from '~/components/LibraryHero'
77
import { LibraryPageContainer } from '~/components/LibraryPageContainer'
88
import { LibraryStatsSection } from '~/components/LibraryStatsSection'
99
import { LibraryTestimonials } from '~/components/LibraryTestimonials'
10+
import { LazyLandingCodeExample } from '~/components/LazyLandingCodeExample'
1011
import { LazyLandingCommunitySection } from '~/components/LazyLandingCommunitySection'
1112
import { LazySponsorSection } from '~/components/LazySponsorSection'
1213
import LandingPageGad from '~/components/LandingPageGad'
1314
import { StackBlitzSection } from '~/components/StackBlitzSection'
1415
import { getBranch, getLibrary } from '~/libraries'
1516
import { formProject } from '~/libraries/form'
16-
import type { LandingComponentProps } from '~/routes/$libraryId/$version'
1717

1818
const library = getLibrary('form')
1919

20-
export default function FormLanding({
21-
landingCodeExampleRsc,
22-
}: LandingComponentProps) {
20+
export default function FormLanding() {
2321
const { version } = useParams({ strict: false })
2422
const branch = getBranch(formProject, version)
2523

@@ -46,7 +44,7 @@ export default function FormLanding({
4644

4745
<LibraryTestimonials testimonials={formProject.testimonials} />
4846

49-
{landingCodeExampleRsc}
47+
<LazyLandingCodeExample libraryId="form" />
5048

5149
<FeatureGrid
5250
title="No dependencies. All the Features."

src/components/landing/QueryLanding.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@ import { LibraryHero } from '~/components/LibraryHero'
77
import { LibraryPageContainer } from '~/components/LibraryPageContainer'
88
import { LibraryStatsSection } from '~/components/LibraryStatsSection'
99
import { LibraryTestimonials } from '~/components/LibraryTestimonials'
10+
import { LazyLandingCodeExample } from '~/components/LazyLandingCodeExample'
1011
import { LazyLandingCommunitySection } from '~/components/LazyLandingCommunitySection'
1112
import { LazySponsorSection } from '~/components/LazySponsorSection'
1213
import LandingPageGad from '~/components/LandingPageGad'
1314
import { QueryGGBanner } from '~/components/QueryGGBanner'
1415
import { StackBlitzSection } from '~/components/StackBlitzSection'
1516
import { getBranch, getLibrary } from '~/libraries'
1617
import { queryProject } from '~/libraries/query'
17-
import type { LandingComponentProps } from '~/routes/$libraryId/$version'
1818

1919
const library = getLibrary('query')
2020

21-
export default function QueryLanding({
22-
landingCodeExampleRsc,
23-
}: LandingComponentProps) {
21+
export default function QueryLanding() {
2422
const { version } = useParams({ strict: false })
2523
const branch = getBranch(queryProject, version)
2624

@@ -40,7 +38,7 @@ export default function QueryLanding({
4038

4139
<LibraryStatsSection library={library} />
4240

43-
{landingCodeExampleRsc}
41+
<LazyLandingCodeExample libraryId="query" />
4442

4543
<LibraryFeatureHighlights
4644
featureHighlights={queryProject.featureHighlights}

src/components/landing/RouterLanding.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,17 @@ import { LibraryHero } from '~/components/LibraryHero'
88
import { LibraryPageContainer } from '~/components/LibraryPageContainer'
99
import { LibraryStatsSection } from '~/components/LibraryStatsSection'
1010
import { LibraryTestimonials } from '~/components/LibraryTestimonials'
11+
import { LazyLandingCodeExample } from '~/components/LazyLandingCodeExample'
1112
import { LazyLandingCommunitySection } from '~/components/LazyLandingCommunitySection'
1213
import { LazySponsorSection } from '~/components/LazySponsorSection'
1314
import LandingPageGad from '~/components/LandingPageGad'
1415
import { StackBlitzSection } from '~/components/StackBlitzSection'
1516
import { getBranch, getLibrary } from '~/libraries'
1617
import { routerProject } from '~/libraries/router'
17-
import type { LandingComponentProps } from '~/routes/$libraryId/$version'
1818

1919
const library = getLibrary('router')
2020

21-
export default function RouterLanding({
22-
landingCodeExampleRsc,
23-
}: LandingComponentProps) {
21+
export default function RouterLanding() {
2422
const { version } = useParams({ strict: false })
2523
const branch = getBranch(routerProject, version)
2624

@@ -55,7 +53,7 @@ export default function RouterLanding({
5553
<LibraryStatsSection library={library} />
5654
</div>
5755

58-
{landingCodeExampleRsc}
56+
<LazyLandingCodeExample libraryId="router" />
5957

6058
<LibraryFeatureHighlights
6159
featureHighlights={routerProject.featureHighlights}

src/components/landing/TableLanding.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,18 @@ import { LibraryHero } from '~/components/LibraryHero'
99
import { LibraryPageContainer } from '~/components/LibraryPageContainer'
1010
import { LibraryStatsSection } from '~/components/LibraryStatsSection'
1111
import { LibraryTestimonials } from '~/components/LibraryTestimonials'
12+
import { LazyLandingCodeExample } from '~/components/LazyLandingCodeExample'
1213
import { LazyLandingCommunitySection } from '~/components/LazyLandingCommunitySection'
1314
import { LazySponsorSection } from '~/components/LazySponsorSection'
1415
import LandingPageGad from '~/components/LandingPageGad'
1516
import { StackBlitzEmbed } from '~/components/StackBlitzEmbed'
1617
import { Framework, getBranch, getLibrary } from '~/libraries'
1718
import { tableProject } from '~/libraries/table'
18-
import type { LandingComponentProps } from '~/routes/$libraryId/$version'
1919
import { getExampleStartingPath } from '~/utils/sandbox'
2020

2121
const library = getLibrary('table')
2222

23-
export default function TableLanding({
24-
landingCodeExampleRsc,
25-
}: LandingComponentProps) {
23+
export default function TableLanding() {
2624
const { version } = useParams({ strict: false })
2725
const branch = getBranch(tableProject, version)
2826
const [framework, setFramework] = useState<Framework>('react')
@@ -44,7 +42,7 @@ export default function TableLanding({
4442

4543
<LibraryStatsSection library={library} />
4644

47-
{landingCodeExampleRsc}
45+
<LazyLandingCodeExample libraryId="table" />
4846

4947
<LibraryFeatureHighlights
5048
featureHighlights={tableProject.featureHighlights}

src/components/landing/VirtualLanding.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@ import { LibraryHero } from '~/components/LibraryHero'
99
import { LibraryPageContainer } from '~/components/LibraryPageContainer'
1010
import { LibraryStatsSection } from '~/components/LibraryStatsSection'
1111
import { LibraryTestimonials } from '~/components/LibraryTestimonials'
12+
import { LazyLandingCodeExample } from '~/components/LazyLandingCodeExample'
1213
import { LazyLandingCommunitySection } from '~/components/LazyLandingCommunitySection'
1314
import { LazySponsorSection } from '~/components/LazySponsorSection'
1415
import LandingPageGad from '~/components/LandingPageGad'
1516
import { StackBlitzEmbed } from '~/components/StackBlitzEmbed'
1617
import { Framework, getBranch, getLibrary } from '~/libraries'
1718
import { virtualProject } from '~/libraries/virtual'
18-
import type { LandingComponentProps } from '~/routes/$libraryId/$version'
1919

2020
const library = getLibrary('virtual')
2121

22-
export default function VirtualLanding({
23-
landingCodeExampleRsc,
24-
}: LandingComponentProps) {
22+
export default function VirtualLanding() {
2523
const { version } = useParams({ strict: false })
2624
const [framework, setFramework] = useState<Framework>('react')
2725
const branch = getBranch(virtualProject, version)
@@ -43,7 +41,7 @@ export default function VirtualLanding({
4341

4442
<LibraryStatsSection library={library} />
4543

46-
{landingCodeExampleRsc}
44+
<LazyLandingCodeExample libraryId="virtual" />
4745

4846
<LibraryFeatureHighlights
4947
featureHighlights={virtualProject.featureHighlights}

src/routes/-library-landing.tsx

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
import type { ComponentType, ReactNode } from 'react'
1+
import type { ComponentType } from 'react'
22
import { getRouteApi, Link, notFound, redirect } from '@tanstack/react-router'
33
import { DocsLayout } from '~/components/DocsLayout'
44
import { RedirectVersionBanner } from '~/components/RedirectVersionBanner'
55
import { Scarf } from '~/components/Scarf'
66
import { findLibrary, getBranch, getLibrary } from '~/libraries'
77
import type { LibraryId } from '~/libraries'
88
import { getTanstackDocsConfig } from '~/utils/config'
9-
import { fetchLandingCodeExample } from '~/utils/landing-code-example.functions'
109
import { seo } from '~/utils/seo'
1110

12-
export type LandingComponentProps = {
13-
landingCodeExampleRsc?: ReactNode
14-
}
11+
export type LandingComponentProps = Record<string, never>
1512

1613
type LandingComponent = ComponentType<LandingComponentProps>
1714

@@ -113,7 +110,7 @@ export function createLibraryLandingPage<TId extends StaticLandingRoutePath>(
113110

114111
function LibraryLandingPage() {
115112
const { version } = routeApi.useParams()
116-
const { config, landingCodeExampleRsc } = routeApi.useLoaderData()
113+
const { config } = routeApi.useLoaderData()
117114

118115
if (!config) {
119116
throw notFound()
@@ -134,7 +131,7 @@ export function createLibraryLandingPage<TId extends StaticLandingRoutePath>(
134131
repo={library.repo}
135132
isLandingPage
136133
>
137-
<LandingComponent landingCodeExampleRsc={landingCodeExampleRsc} />
134+
<LandingComponent />
138135
</DocsLayout>
139136
<RedirectVersionBanner
140137
version={version!}
@@ -158,18 +155,10 @@ export function createLibraryLandingPage<TId extends StaticLandingRoutePath>(
158155
})
159156
},
160157
loader: async ({ params }: { params: { version: string } }) => {
161-
const [config, landingCodeExample] = await Promise.all([
162-
loadLibraryConfig(libraryId, params.version),
163-
fetchLandingCodeExample({
164-
data: {
165-
libraryId,
166-
},
167-
}),
168-
])
158+
const config = await loadLibraryConfig(libraryId, params.version)
169159

170160
return {
171161
config,
172-
landingCodeExampleRsc: landingCodeExample?.contentRsc ?? null,
173162
}
174163
},
175164
head: () => ({

0 commit comments

Comments
 (0)