Practical answers to React Server Components children composition, revalidateTag vs revalidatePath, Server Actions authorization, and TypeScript discriminated unions.
Importing a Server Component directly inside a 'use client' file converts that child into a client bundle module. Instead, pass it as children or a named JSX prop from the parent Server Component so React serializes the RSC payload on the server without shipping server dependencies to the browser.
// ServerPage.tsx
export default function Page() {
return (
<ClientDrawer>
<ServerRevenueTable /> {/* stays server-only */}
</ClientDrawer>
);
}
revalidatePath invalidates an entire route segment cache, forcing unrelated widgets on that route to refetch. Tag-based caching (fetch(..., { next: { tags: ['invoices'] } })) lets a Server Action purge only affected queries across multiple routes simultaneously.
import { revalidateTag } from 'next/cache';
export async function markPaid(id: string) {
await db.invoices.update({ where: { id }, data: { status: 'paid' } });
revalidateTag('invoices');
}
Boolean bags (isLoading, isError, data) allow impossible states like loading=true and error!=null at the same time. Discriminated unions enforce compile-time exhaustiveness with a never check.
type AsyncState<T> =
| { status: 'idle' }
| { status: 'loading' }
| { status: 'error'; message: string }
| { status: 'ready'; data: T };