Skip to content

Commit af6ec4f

Browse files
authored
Use a transparent animated palm on the homepage (#1514)
* Use responsive animated WebP for the homepage palm loop * Preserve photographic leaf detail in the homepage palm loop * Restore each original palm frame before encoding WebP * Layer a shared transparent palm over the homepage sky * Add a subtle static grain to the homepage sky * Shrink the palm loop and preserve finer frond edges * Prefer a smaller animated AVIF for the homepage palm * Show the palm poster while the animation is loading * Prioritize the homepage palm poster and defer offscreen work * Load live homepage stats on visibility and keep signup immediately interactive * Make the homepage palm pausable from first paint * Use WebP as the only homepage palm animation * Load one palm WebP for the visitor’s motion preference * Avoid an extra palm request during streamed HTML parsing * Show the first palm frame early and shrink its WebP loop * Use a plain CSS gradient behind the homepage palm * Reduce the homepage palm transfer while keeping early motion * Preserve the full forward palm motion within the homepage media budget
1 parent 98188e4 commit af6ec4f

7 files changed

Lines changed: 200 additions & 487 deletions

File tree

22 KB
Loading
1.77 MB
Loading
Lines changed: 46 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,59 @@
11
import * as React from 'react'
2-
import { PauseIcon, PlayIcon } from '@phosphor-icons/react'
2+
import { preload } from 'react-dom'
33
import { Squircle } from '~/components/Squircle'
44

5-
export function HeroPalmMedia() {
6-
const videoRef = React.useRef<HTMLVideoElement>(null)
7-
const [isVideoReady, setIsVideoReady] = React.useState(false)
8-
const [isPlaying, setIsPlaying] = React.useState(false)
9-
10-
const playVideo = React.useCallback((video: HTMLVideoElement) => {
11-
if (video.networkState === HTMLMediaElement.NETWORK_NO_SOURCE) video.load()
12-
const promise = video.play()
13-
if (promise !== undefined) {
14-
promise
15-
.then(() => setIsVideoReady(true))
16-
.catch((error: unknown) => {
17-
if (error instanceof DOMException && error.name === 'AbortError')
18-
return
19-
console.error('Unable to play the homepage hero animation', error)
20-
setIsPlaying(false)
21-
setIsVideoReady(false)
22-
})
23-
}
24-
}, [])
25-
26-
React.useEffect(() => {
27-
const video = videoRef.current
28-
if (!video) return
29-
const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)')
30-
31-
const pauseForReducedMotion = () => {
32-
if (reducedMotion.matches) video.pause()
33-
}
5+
const motion = '/images/hero-palm-cutout.webp'
6+
const still = '/images/hero-palm-cutout-still.webp'
7+
const allowMotion = '(prefers-reduced-motion: no-preference)'
348

35-
pauseForReducedMotion()
36-
setIsPlaying(!video.paused)
37-
setIsVideoReady(video.readyState >= HTMLMediaElement.HAVE_FUTURE_DATA)
38-
reducedMotion.addEventListener('change', pauseForReducedMotion)
39-
return () =>
40-
reducedMotion.removeEventListener('change', pauseForReducedMotion)
41-
}, [])
42-
43-
const togglePlayback = () => {
44-
const video = videoRef.current
45-
if (!video) return
9+
export function HeroPalmMedia() {
10+
preload(still, { as: 'image', fetchPriority: 'high' })
11+
preload(motion, { as: 'image', fetchPriority: 'high', media: allowMotion })
4612

47-
if (video.paused) {
48-
playVideo(video)
49-
} else {
50-
video.pause()
51-
}
52-
}
13+
const [motionFailed, setMotionFailed] = React.useState(false)
5314

5415
return (
55-
<>
56-
<Squircle
57-
aria-hidden
58-
className="absolute inset-0 -z-10 overflow-hidden rounded-xl [corner-shape:squircle]"
59-
>
60-
<picture className="contents">
61-
<source
62-
type="image/webp"
63-
srcSet="/images/hero-palm-gradient-960.webp 960w, /images/hero-palm-gradient-1600.webp 1600w, /images/hero-palm-gradient-2400.webp 2400w"
64-
sizes="100vw"
65-
/>
16+
<Squircle
17+
aria-hidden
18+
className="pointer-events-none absolute inset-0 -z-10 grid place-content-center overflow-hidden rounded-xl [container-type:size] [corner-shape:squircle]"
19+
>
20+
{/* Keep the palm aligned with the original 944 × 416 composition. */}
21+
<div className="home-palm-sky relative aspect-[944/416] w-[max(100cqw,calc(100cqh*944/416))]">
22+
<div className="absolute bottom-0 left-[calc(100%*360/944)] w-[calc(100%*260/944)]">
6623
<img
67-
src="/images/hero-palm-gradient.jpg"
24+
src={still}
6825
alt=""
69-
width={2400}
70-
height={1058}
71-
loading="eager"
26+
width={260}
27+
height={348}
7228
fetchPriority="high"
73-
className={`relative z-10 h-full w-full object-cover object-center ${isVideoReady ? 'opacity-0 motion-reduce:opacity-100' : ''}`}
74-
/>
75-
</picture>
76-
<video
77-
ref={videoRef}
78-
autoPlay
79-
loop
80-
muted
81-
playsInline
82-
onPause={() => setIsPlaying(false)}
83-
onPlay={() => setIsPlaying(true)}
84-
onCanPlay={() => setIsVideoReady(true)}
85-
onError={() => setIsVideoReady(false)}
86-
className="absolute inset-0 h-full w-full object-cover object-center motion-reduce:hidden"
87-
>
88-
<source
89-
src="/images/hero-palm-motion.mp4"
90-
type="video/mp4"
91-
media="(prefers-reduced-motion: no-preference)"
29+
className="block h-auto w-full"
9230
/>
93-
</video>
94-
</Squircle>
95-
<button
96-
type="button"
97-
onClick={togglePlayback}
98-
aria-label={isPlaying ? 'Pause hero animation' : 'Play hero animation'}
99-
className="absolute right-4 top-4 z-20 grid size-8 place-items-center rounded-full bg-ds-neutral-500/65 text-white opacity-0 backdrop-blur-sm transition-opacity hover:bg-ds-neutral-500/80 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white group-hover:opacity-100 motion-reduce:hidden"
100-
>
101-
{isPlaying ? (
102-
<PauseIcon className="size-4" weight="fill" />
103-
) : (
104-
<PlayIcon className="size-4" weight="fill" />
105-
)}
106-
</button>
107-
</>
31+
<picture className="absolute inset-0 motion-reduce:hidden">
32+
{!motionFailed && (
33+
<source type="image/webp" media={allowMotion} srcSet={motion} />
34+
)}
35+
<img
36+
src={still}
37+
alt=""
38+
width={260}
39+
height={348}
40+
fetchPriority="high"
41+
ref={(image) => {
42+
// A failed request can finish before hydration attaches onError.
43+
if (
44+
image?.complete &&
45+
!image.naturalWidth &&
46+
image.currentSrc.endsWith(motion)
47+
) {
48+
setMotionFailed(true)
49+
}
50+
}}
51+
onError={() => setMotionFailed(true)}
52+
className="block h-auto w-full"
53+
/>
54+
</picture>
55+
</div>
56+
</div>
57+
</Squircle>
10858
)
10959
}

‎src/components/home/HomeApplicationStarter.tsx‎

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

55
import { ApplicationStarter } from '~/components/ApplicationStarter'
66
import { HomeApplicationStarterFallback } from './HomeSectionFallbacks'
@@ -17,8 +17,7 @@ const headlines = [
1717
export function HomeApplicationStarter() {
1818
return (
1919
<Hydrate
20-
when={visible({ rootMargin: '180px 0px' })}
21-
prefetch={idle({ timeout: 3500 })}
20+
when={visible({ rootMargin: '0px' })}
2221
fallback={<HomeApplicationStarterFallback />}
2322
>
2423
<RotatingHomeApplicationStarter />

‎src/routes/index.tsx‎

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ 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'
1517
import { HeroPalmMedia } from '~/components/home/HeroPalmMedia'
1618
import { HomeApplicationStarter } from '~/components/home/HomeApplicationStarter'
1719
import { HomeCommunitySection } from '~/components/home/HomeCommunitySection'
1820
import { HomeNewsletterSection } from '~/components/home/HomeNewsletterSection'
1921
import { HomeSocialProofSection } from '~/components/home/HomeSocialProofSection'
22+
import { HomeStatsFallback } from '~/components/home/HomeSectionFallbacks'
2023
import { HomeStatsSection } from '~/components/home/HomeStatsSection'
2124
import { useQuery } from '@tanstack/react-query'
2225
import { Button, Eyebrow } from '~/components/ds/ui'
@@ -31,15 +34,7 @@ import { seo } from '~/utils/seo'
3134
import { getTanStackHomepageJsonLd } from '~/utils/organization-structured-data'
3235

3336
export const Route = createFileRoute('/')({
34-
loader: async ({ context: { queryClient } }) => {
35-
const [, , recentPosts] = await Promise.all([
36-
queryClient.ensureQueryData(ossStatsQuery()),
37-
queryClient.ensureQueryData(homepageNpmStatsSummaryQuery()),
38-
fetchRecentPosts(),
39-
])
40-
41-
return { recentPosts }
42-
},
37+
loader: () => fetchRecentPosts(),
4338
head: () => ({
4439
meta: seo({
4540
title: 'TanStack | The open-source application stack for the web.',
@@ -57,7 +52,7 @@ export const Route = createFileRoute('/')({
5752
})
5853

5954
function Index() {
60-
const { recentPosts } = Route.useLoaderData()
55+
const recentPosts = Route.useLoaderData()
6156
const { openLibraries } = useLibrariesOverlay()
6257

6358
const startWithPrompt = (e: React.MouseEvent) => {
@@ -78,19 +73,14 @@ function Index() {
7873
<Scarf id={homepageScarfPixel} path="/" />
7974
<main className="max-w-full z-10 space-y-24">
8075
<div className="space-y-8">
81-
{/* Hero — Figma node 802:2027. Full-bleed palm/gradient photo card:
82-
headline bottom-left, description + CTA bottom-right. The photo is
76+
{/* Hero — Figma node 802:2027. Full-bleed palm and sky:
77+
headline bottom-left, description + CTA bottom-right. The sky is
8378
always light, so text uses a mode-stable dark token (neutral-500)
8479
rather than a theme-flipping semantic. */}
8580
<div className="mx-0 rounded-none bg-background-subtle p-0 sm:mx-2 sm:rounded-2xl sm:p-1">
8681
{/* `svh`, not `dvh` — the dynamic viewport grows as iOS collapses
8782
the URL bar mid-scroll, visibly stretching the hero. */}
8883
<div className="group relative isolate flex h-[calc(100svh-var(--navbar-height))] max-h-[720px] min-h-[560px] flex-col justify-between gap-8 overflow-hidden rounded-none px-6 py-10 [text-shadow:0_2px_8px_rgb(255_255_255/0.2)] sm:rounded-xl sm:px-10 md:flex-row md:items-end md:justify-between md:gap-8 md:[text-shadow:none] xl:gap-12 xl:px-16 xl:py-16">
89-
{/* The parent supplies the 4px frame shared by the hero and stats.
90-
This wrapper clips the image to the inner radius so the <img>
91-
fills it exactly instead of overflowing. Plain <img> (not OptimizedImage):
92-
the Cloudflare transform resolves against the production origin,
93-
so a newly-added asset 404s until deployed. */}
9484
<HeroPalmMedia />
9585
<h1 className="max-w-[613px] font-ds-display text-ds-display-sm font-bold text-ds-neutral-500 md:w-[47%] md:text-[clamp(2rem,4.3vw,4rem)] md:leading-[1.1] md:tracking-[-0.025em] xl:leading-[1.08]">
9686
The{' '}
@@ -106,7 +96,7 @@ function Index() {
10696
applications that work naturally for developers and reliably
10797
for agents
10898
</p>
109-
{/* The photo is always light, so scope the CTAs to the DS
99+
{/* The sky is always light, so scope the CTAs to the DS
110100
light mode — the Buttons then render as their standard DS
111101
light-mode selves (no per-button color overrides). */}
112102
<div className="ds-mode-light flex flex-wrap items-center gap-2">
@@ -143,7 +133,12 @@ function Index() {
143133
</div>
144134
</div>
145135
<div className="flex items-center justify-center px-2.5 py-6">
146-
<HomeStatsSection />
136+
<Hydrate
137+
when={visible({ rootMargin: '0px' })}
138+
fallback={<HomeStatsFallback />}
139+
>
140+
<HomeStatsSection />
141+
</Hydrate>
147142
</div>
148143
</div>
149144
<div
@@ -457,10 +452,12 @@ function WhyTanStackSection() {
457452

458453
{/* proof panel — 478:1744 */}
459454
<PrinciplePanel>
460-
<PrincipleProof
461-
proof={principle.proof}
462-
accentClassName={principle.accentClassName}
463-
/>
455+
<Hydrate when={visible({ rootMargin: '200px' })}>
456+
<PrincipleProof
457+
proof={principle.proof}
458+
accentClassName={principle.accentClassName}
459+
/>
460+
</Hydrate>
464461
</PrinciplePanel>
465462
</li>
466463
))}
@@ -493,7 +490,7 @@ function WhyTanStackSection() {
493490
*/
494491
function PrinciplePanel({ children }: { children: React.ReactNode }) {
495492
return (
496-
<div className="flex h-[233px] w-full shrink-0 items-center justify-center lg:w-[460px]">
493+
<div className="flex h-[233px] w-full shrink-0 items-center justify-center lg:w-[460px] [&>div]:w-full">
497494
{children}
498495
</div>
499496
)
@@ -704,8 +701,8 @@ function PrincipleProof({
704701
}
705702

706703
/**
707-
* Production-Grade proof: the live npm download odometer already prefetched by
708-
* the route loader, plus weekly volume and stars. Real numbers rather than
704+
* Production-Grade proof: the live npm download odometer shared with
705+
* the hero stats, plus weekly volume and stars. Real numbers rather than
709706
* adjectives — the point of the principle is scale.
710707
*/
711708
function AdoptionProof({ accentClassName }: { accentClassName: string }) {

‎src/styles/app.css‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,6 +2751,16 @@ html:not(.dark) .library-landing-graphic [style*='drop-shadow'] {
27512751
transition: opacity 120ms linear;
27522752
}
27532753

2754+
.home-palm-sky {
2755+
background: linear-gradient(
2756+
#8fd7fe,
2757+
#b0dbff 25%,
2758+
#d3e0ff 50%,
2759+
#e7dffb 75%,
2760+
#f5d9f2
2761+
);
2762+
}
2763+
27542764
@keyframes home-open-source-gradient-shift {
27552765
0%,
27562766
100% {

0 commit comments

Comments
 (0)