0
Challenge · 68The Data API & Your Next.js App
Server Components read; Server Actions mutate
Appused in ~90% of apps
The instinct from every other framework is: render a shell, useEffect a fetch, show a spinner, setState when it resolves — and to write back, POST to an API route, then refetch to see your own change. A Next.js Server Component throws that whole loop away for reads: it calls supabase-js directly, in the component body, before any HTML is sent. Do the same instinct for writes — wire up an onClick that calls an API route — and you have reinvented exactly the ceremony this architecture exists to delete.
Core idea. An async Server Component IS the data-fetching layer — it awaits a Supabase query directly in its body, and one call embedding the author and the comment count (concept 23's JOIN, through PostgREST) is what keeps the whole feed to a single round trip. A Server Action ('use server') is the only sanctioned way to mutate: it runs on the server, uses the exact same RLS-governed client as any read, and must explicitly tell Next.js what's now stale (revalidatePath, or the newer updateTag) — nothing refetches on its own.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
1 · Server Component renders
// app/page.tsx (Server Component, no "use client")
const { data: posts } = await supabase
.from('posts')
.select('id, title, profiles(username, avatar_url), comments(count)')
.eq('is_public', true)
.order('created_at', { ascending: false })One query. The author and the comment count travel embedded in the same response — no second request per post, no waterfall.
1 / 5
↑ play a little first, then dig in