Skip to content

Commit b554a65

Browse files
committed
Keep homepage layout stable during hydration
1 parent 299f3de commit b554a65

5 files changed

Lines changed: 13 additions & 251 deletions

File tree

‎src/components/home/HomeApplicationStarter.tsx‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import * as React from 'react'
2-
import { Hydrate } from '@tanstack/react-start'
3-
import { visible } from '@tanstack/react-start/hydration'
42

53
import { ApplicationStarter } from '~/components/ApplicationStarter'
6-
import { HomeApplicationStarterFallback } from './HomeSectionFallbacks'
74

85
const headlineStorageKey = 'tanstack-home-starter-headline-index'
96
const headlines = [
@@ -15,17 +12,6 @@ const headlines = [
1512
] as const
1613

1714
export function HomeApplicationStarter() {
18-
return (
19-
<Hydrate
20-
when={visible({ rootMargin: '0px' })}
21-
fallback={<HomeApplicationStarterFallback />}
22-
>
23-
<RotatingHomeApplicationStarter />
24-
</Hydrate>
25-
)
26-
}
27-
28-
function RotatingHomeApplicationStarter() {
2915
const [headlineIndex, setHeadlineIndex] = React.useState(0)
3016

3117
React.useEffect(() => {
@@ -45,14 +31,6 @@ function RotatingHomeApplicationStarter() {
4531
headlineStorageKey,
4632
String((currentIndex + 1) % headlines.length),
4733
)
48-
49-
const section = document.getElementById('start-with-a-prompt')
50-
if (section?.dataset.focusPrompt === 'true') {
51-
const field = section.querySelector<HTMLTextAreaElement>('textarea')
52-
field?.focus()
53-
field?.select()
54-
delete section.dataset.focusPrompt
55-
}
5634
}, [])
5735

5836
return (

‎src/components/home/HomeCommunitySection.tsx‎

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { lazy, Suspense } from 'react'
22
import { ClientOnly, createLink } from '@tanstack/react-router'
3-
import { Hydrate } from '@tanstack/react-start'
4-
import { visible } from '@tanstack/react-start/hydration'
53
import { ArrowRightIcon } from '@phosphor-icons/react'
64
import { Button } from '~/components/ds/ui'
75
import { allMaintainers } from '~/libraries/maintainers'
@@ -14,28 +12,19 @@ const MaintainersMap = lazy(() =>
1412
})),
1513
)
1614

15+
// Reserve the map, its help text line, and the gap between them.
1716
const globeFallback = (
18-
<div aria-hidden="true" className="box-content h-(--globe-height) pb-16" />
17+
<div
18+
aria-hidden="true"
19+
className="box-content h-(--globe-height) pb-[calc(1rem+1lh)] text-xs leading-relaxed"
20+
/>
1921
)
2022

2123
export function HomeCommunitySection() {
22-
return (
23-
<div className="@container mx-auto w-full max-w-(--breakpoint-lg) px-4 [--globe-width:calc(100cqw+2rem)] [--globe-height:calc(var(--globe-width)*1.25)] sm:[--globe-width:min(120cqw,calc(100vw-1rem))] sm:[--globe-height:calc(var(--globe-width)*0.875)]">
24-
<Hydrate
25-
when={visible({ rootMargin: '25%' })}
26-
fallback={<div className="pt-16">{globeFallback}</div>}
27-
>
28-
<HomeCommunityContent />
29-
</Hydrate>
30-
</div>
31-
)
32-
}
33-
34-
function HomeCommunityContent() {
3524
return (
3625
<section
3726
aria-labelledby="maintainers"
38-
className="isolate flex flex-col gap-4"
27+
className="@container isolate mx-auto flex w-full max-w-(--breakpoint-lg) flex-col gap-4 px-4 [--globe-width:calc(100cqw+2rem)] [--globe-height:calc(var(--globe-width)*1.25)] sm:[--globe-width:min(120cqw,calc(100vw-1rem))] sm:[--globe-height:calc(var(--globe-width)*0.875)]"
3928
>
4029
<header className="sm:mb-10 lg:-mt-6">
4130
<h2

‎src/components/home/HomeSectionFallbacks.tsx‎

Lines changed: 0 additions & 127 deletions
This file was deleted.

‎src/components/home/HomeSocialProofSection.tsx‎

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { Link } from '@tanstack/react-router'
2-
import { Hydrate } from '@tanstack/react-start'
3-
import { visible } from '@tanstack/react-start/hydration'
42
import { ArrowRightIcon } from '@phosphor-icons/react'
53
import { BlogPostCard } from '~/components/ds/ui/BlogPostCard'
64
import { Button } from '~/components/ds/ui'
@@ -14,68 +12,6 @@ type HomeSocialProofSectionProps = {
1412
export function HomeSocialProofSection({
1513
recentPosts,
1614
}: HomeSocialProofSectionProps) {
17-
return (
18-
<Hydrate
19-
when={visible({ rootMargin: '25%' })}
20-
fallback={<SocialProofSkeleton />}
21-
>
22-
<HomeSocialProofContent recentPosts={recentPosts} />
23-
</Hydrate>
24-
)
25-
}
26-
27-
function SocialProofSkeleton() {
28-
return (
29-
<div className="space-y-24">
30-
<div className="px-4 lg:max-w-(--breakpoint-lg) md:mx-auto">
31-
<div className="h-10 w-40 rounded bg-gray-200/70 dark:bg-gray-800/70 animate-pulse mb-6" />
32-
<div className="overflow-hidden rounded-2xl corner-squircle border border-gray-200 dark:border-gray-800">
33-
{[2, 3].map((cols, band) => (
34-
<div key={`partner-band-${band}`}>
35-
<div className="h-12 bg-gray-200/70 dark:bg-gray-800/70 animate-pulse" />
36-
<div
37-
className="grid gap-px bg-gray-200/70 dark:bg-gray-800/70"
38-
style={{
39-
gridTemplateColumns: `repeat(${cols}, minmax(0, 1fr))`,
40-
}}
41-
>
42-
{Array.from({ length: cols * 2 }).map((_, index) => (
43-
<div
44-
key={`partner-skeleton-${band}-${index}`}
45-
className="min-h-[130px] bg-white/70 dark:bg-gray-950/60 animate-pulse"
46-
/>
47-
))}
48-
</div>
49-
</div>
50-
))}
51-
</div>
52-
</div>
53-
<div className="px-4 lg:max-w-(--breakpoint-lg) md:mx-auto">
54-
<div className="h-10 w-56 rounded bg-gray-200/70 dark:bg-gray-800/70 animate-pulse mb-6" />
55-
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
56-
{Array.from({ length: 3 }).map((_, index) => (
57-
<div
58-
key={`post-skeleton-${index}`}
59-
className="animate-pulse rounded-xl corner-squircle p-2"
60-
>
61-
<div className="aspect-video rounded-lg corner-squircle bg-gray-100 dark:bg-gray-800" />
62-
<div className="px-0.5 pt-2.5">
63-
<div className="h-5 w-5/6 rounded bg-gray-200 dark:bg-gray-700" />
64-
<div className="mt-3 h-3 w-2/3 rounded bg-gray-200 dark:bg-gray-700" />
65-
<div className="mt-4 space-y-2">
66-
<div className="h-3 rounded bg-gray-100 dark:bg-gray-800" />
67-
<div className="h-3 rounded bg-gray-100 dark:bg-gray-800" />
68-
</div>
69-
</div>
70-
</div>
71-
))}
72-
</div>
73-
</div>
74-
</div>
75-
)
76-
}
77-
78-
function HomeSocialProofContent({ recentPosts }: HomeSocialProofSectionProps) {
7915
return (
8016
<div className="space-y-24">
8117
<PartnersSponsorsContent

‎src/routes/index.tsx‎

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ import {
1212
LightningIcon,
1313
type Icon,
1414
} from '@phosphor-icons/react'
15-
import { Hydrate } from '@tanstack/react-start'
16-
import { visible } from '@tanstack/react-start/hydration'
1715
import { HeroPalmMedia } from '~/components/home/HeroPalmMedia'
1816
import { HomeApplicationStarter } from '~/components/home/HomeApplicationStarter'
1917
import { HomeCommunitySection } from '~/components/home/HomeCommunitySection'
2018
import { HomeNewsletterSection } from '~/components/home/HomeNewsletterSection'
2119
import { HomeSocialProofSection } from '~/components/home/HomeSocialProofSection'
22-
import { HomeStatsFallback } from '~/components/home/HomeSectionFallbacks'
2320
import { HomeStatsSection } from '~/components/home/HomeStatsSection'
2421
import { HomeStatNumber } from '~/components/home/HomeStatNumber'
2522
import { LiveDownloadCount } from '~/components/home/LiveDownloadCount'
@@ -80,12 +77,8 @@ function Index() {
8077
const section = document.getElementById('start-with-a-prompt')
8178
section?.scrollIntoView({ behavior: 'smooth', block: 'start' })
8279
const field = section?.querySelector<HTMLTextAreaElement>('textarea')
83-
if (field) {
84-
field.focus()
85-
field.select()
86-
} else if (section) {
87-
section.dataset.focusPrompt = 'true'
88-
}
80+
field?.focus({ preventScroll: true })
81+
field?.select()
8982
}
9083

9184
return (
@@ -152,12 +145,7 @@ function Index() {
152145
</div>
153146
</div>
154147
<div className="flex flex-col px-4 py-6 sm:px-1 md:flex-row md:items-center md:justify-center md:px-2.5">
155-
<Hydrate
156-
when={visible({ rootMargin: '0px' })}
157-
fallback={<HomeStatsFallback />}
158-
>
159-
<HomeStatsSection initialStats={initialStats} />
160-
</Hydrate>
148+
<HomeStatsSection initialStats={initialStats} />
161149
</div>
162150
</div>
163151
<div
@@ -446,12 +434,10 @@ function WhyTanStackSection() {
446434

447435
{/* proof panel — 478:1744 */}
448436
<PrinciplePanel>
449-
<Hydrate when={visible({ rootMargin: '200px' })}>
450-
<PrincipleProof
451-
proof={principle.proof}
452-
accentClassName={principle.accentClassName}
453-
/>
454-
</Hydrate>
437+
<PrincipleProof
438+
proof={principle.proof}
439+
accentClassName={principle.accentClassName}
440+
/>
455441
</PrinciplePanel>
456442
</li>
457443
))}

0 commit comments

Comments
 (0)