Files
supabase/apps/www/components/Go/TweetsSection.tsx
Pamela Chia a9078612f2 fix(www): stop cross-zone link prefetch (#51066)
About 95% of the 404s served on supabase.com are App Router RSC
prefetches (`?_rsc=`) that www `<Link>`s fire at paths another zone
serves: `/docs`, `/dashboard`, `/library`, and the footer's
`humans.txt`, `lawyers.txt` and `security.txt`. Next.js can't prefetch
or client-navigate across multi-zone boundaries, so each prefetch 404s
even though the link itself works. I turned every www link into another
zone into a plain `<a>` and added a lint rule so new ones stay that way.

**Changed:**
- **Cross-zone links are plain anchors**: links that always leave www
(literal `/docs`, `/dashboard` and `.txt` hrefs, absolute
`https://supabase.com/dashboard` URLs, the `getDashboardCtaHref` CTAs)
render `<a>`. Renderers whose href comes from data (nav, footer, plan
and add-on CTAs, product cards) branch on `isCrossZoneHref`, which reads
the zone list from `lib/rewrites.js`. In-zone links stay `<Link>` and
keep prefetching.
- **New literal links can't regress**: `www/no-cross-zone-link` errors
on a `next/link` `<Link>` whose literal or template href points at
another zone. It evaluates `lib/rewrites.js` as production, so `/docs`
counts in every environment.
- **Click tracking survives the full navigation**:
`sign_in_button_clicked`, `start_project_button_clicked` and
`www_pricing_plan_cta_clicked` now send with `keepalive`, like
`sign_in_submitted` already did, so an immediate page load can't cancel
them. The mobile nav Sign in and Start your project buttons used
`legacyBehavior`, which never called their `onClick`: PostHog has no
`Mobile Nav` location for either event in the last 30 days. Those clicks
report from this PR on.
- **Typecheck no longer crashes**: the functions page's default export
inferred a type through `RealtimeLogs`'s unexported `Props`, which makes
the native TypeScript compiler panic during `tsc --noEmit`. I exported
`Props`.

**Note:** the lint rule only sees literal hrefs. A new renderer whose
href comes from data needs its own `isCrossZoneHref` branch, and review
is the only check on that.

## To test
`/docs` is only rewritten on production and absolute
`https://supabase.com/...` links are cross-origin on a preview, so the
preview proves the relative non-docs cases (`/dashboard*`, `/library`,
the footer .txt files). `/docs/...` prefetches still appear on the
preview because it has no docs rewrite.

Tested on Vercel preview:
- [x] Open `/` with the network tab filtered to `_rsc` and scroll to the
footer: no requests for `/dashboard*`, `/library`, `/design-system`,
`/kb`, `/evals`, `/humans.txt`, `/lawyers.txt` or
`/.well-known/security.txt`, while in-zone ones such as `/pricing`,
`/features` and `/blog` still appear
- [x] Same check on `/pricing`, `/auth`, `/database`, `/storage`,
`/realtime`, `/edge-functions`, `/blog` and a blog post: no `_rsc`
requests to `/dashboard*`, `/library` or the footer .txt files
- [x] Open the Developers dropdown on desktop and the mobile menu at
390px: no new `_rsc` requests to `/dashboard*` or `/library`
- [x] Click header Docs, footer Humans.txt, the hero Start your project
button and the pricing Free plan button: each lands where it did before
(`/docs`, `/humans.txt` text, `https://supabase.com/dashboard/sign-up`,
`https://supabase.com/dashboard/new?plan=free`). Signed out, the Free
plan button lands on the dashboard sign-in with
`plan=free&returnTo=%2Fnew`
- [x] Click the hero Start your project button: the
`/platform/telemetry/event` POST with `start_project_button_clicked`
completes with a 2xx after the page starts navigating. 201 with the
navigation held; on the real navigation the event still reached staging
PostHog
- [x] At 390px, open the mobile menu and click Sign in: a
`/platform/telemetry/event` POST with `sign_in_button_clicked` and
`buttonLocation: "Mobile Nav"` fires. Start your project in the same
menu also sends `start_project_button_clicked` with `buttonLocation:
"Mobile Nav"`
- [ ] Signed in, load `/`: no `/dashboard/projects?_rsc=` request (not
run: the preview origin has no signed-in session)
- [x] Open the desktop Product dropdown and the Product section of the
390px mobile menu: Compute shows its Private Alpha badge and the other
products show none (checks the master merge into `MenuItem`)

After deploy, `/` and `/pricing` on supabase.com show no `_rsc` requests
to `/docs*`, `/dashboard*` or `/library`. After a full day, the share of
supabase.com 404s carrying `_rsc=` should drop from about 95% to under
10%, and `sign_in_button_clicked` and `start_project_button_clicked`
should start showing a `Mobile Nav` location in PostHog.

## Linear
- fixes GROWTH-1294
2026-10-05 15:17:04 -07:00

118 lines
4.0 KiB
TypeScript

'use client'
import { useBreakpoint } from 'common'
import { range } from 'lib/helpers'
import type { GoTweetsSection } from 'marketing'
import Link from 'next/link'
import { topTweets } from 'shared-data/tweets'
import { Button, cn } from 'ui'
import { TweetCard } from 'ui-patterns/TweetCard'
import { isCrossZoneHref } from '@/lib/cross-zone'
function MobileCarousel() {
return (
<div
className="tweets-carousel flex gap-3 overflow-x-auto snap-x snap-mandatory px-6 pb-4"
style={{ WebkitOverflowScrolling: 'touch', scrollbarWidth: 'none' }}
>
<style>{`.tweets-carousel::-webkit-scrollbar { display: none; }`}</style>
{topTweets.slice(0, 9).map((tweet: any) => (
<Link
key={tweet.text}
href={tweet.url}
target="_blank"
rel="noopener noreferrer"
className="snap-start shrink-0 w-[85vw] max-w-[320px] sm:w-[55vw] group/tweet-card"
>
<TweetCard handle={`@${tweet.handle}`} quote={tweet.text} img_url={tweet.img_url} />
</Link>
))}
</div>
)
}
function DesktopMarquee() {
const isMd = useBreakpoint(1024)
const visibleTweets = topTweets.slice(0, isMd ? 12 : 18)
return (
<div className="relative w-full max-w-[1400px] mx-auto overflow-hidden">
<div className="group relative transition-all max-h-[500px] w-auto flex flex-nowrap">
{range(0, 3).map((_, idx) => (
<div
key={`tweets-range-${idx}`}
className={cn(
'columns-2 lg:columns-3 xl:columns-5',
'gap-4 h-fit pr-4',
'min-w-[900px] max-w-[900px]',
'xl:min-w-[1600px] xl:max-w-[1600px]',
'animate-[marquee_40000ms_linear_both_infinite] group-hover:pause',
'motion-reduce:animate-none motion-reduce:will-change-none',
'will-change-transform transition-transform'
)}
>
{visibleTweets.map((tweet: any, i: number) => (
<Link
key={tweet.text}
href={tweet.url}
target="_blank"
rel="noopener noreferrer"
className={cn(
'min-w-[200px]',
'mb-4 z-0 break-inside-avoid-column block group/tweet-card',
i > 12 && 'hidden lg:block'
)}
>
<TweetCard handle={`@${tweet.handle}`} quote={tweet.text} img_url={tweet.img_url} />
</Link>
))}
</div>
))}
</div>
<div className="absolute pointer-events-none w-full h-full inset-0 top-auto lg:bg-[radial-gradient(50%_100%_at_50%_0,transparent_0%,transparent_50%,var(--background-default)_100%)]" />
</div>
)
}
export default function TweetsSection({ section }: { section: GoTweetsSection }) {
return (
<div>
{(section.title || section.description || section.ctas) && (
<div className="text-center flex flex-col items-center gap-4 mb-8 px-8">
{section.title && (
<h2 className="text-2xl sm:text-3xl text-foreground">{section.title}</h2>
)}
{section.description && (
<p className="text-foreground-lighter max-w-lg text-pretty">{section.description}</p>
)}
{section.ctas && section.ctas.length > 0 && (
<div className="flex gap-2 mt-2">
{section.ctas.map((cta, i) => (
<Button
key={i}
asChild
variant={cta.variant === 'secondary' ? 'default' : 'primary'}
size="small"
>
{isCrossZoneHref(cta.href) ? (
<a href={cta.href}>{cta.label}</a>
) : (
<Link href={cta.href}>{cta.label}</Link>
)}
</Button>
))}
</div>
)}
</div>
)}
<div className="lg:hidden">
<MobileCarousel />
</div>
<div className="hidden lg:block">
<DesktopMarquee />
</div>
</div>
)
}