Real-Time Dashboards with Next.js 16 and Supabase Channels
Using Supabase Realtime channels and Next.js Server Components to build a live analytics dashboard without a single polling call. The PDEU ACM Student Chapter website architecture explained.
Polling is the default answer to "how do I keep this dashboard fresh", and it is almost always the wrong one. A five-second interval on a page nobody is looking at still costs you a request every five seconds, per open tab.
Supabase Realtime gives you the opposite model: the database tells you when something changed.
The split: server for the first paint, client for updates
The pattern that works cleanly in the App Router is to render the initial state on the server and hand it to a client component that subscribes to changes.
// app/admin/page.tsx — Server Component
import { adminEventService } from "@/lib/supabase/server-services";
import { LiveEventTable } from "./live-event-table";
export default async function AdminPage() {
const result = await adminEventService.getAll({
orderBy: { column: "start_time", ascending: false },
});
return <LiveEventTable initial={result.data ?? []} />;
}
The server component does the fetch with the service-role client, so the first paint has real data and no loading spinner. The client component takes it from there.
Subscribing to changes
"use client";
import { useEffect, useState } from "react";
import { getSupabaseClient } from "@/lib/supabase/client";
import type { Event } from "@/types/models";
export function LiveEventTable({ initial }: { initial: Event[] }) {
const [events, setEvents] = useState(initial);
useEffect(() => {
const supabase = getSupabaseClient();
const channel = supabase
.channel("events-feed")
.on(
"postgres_changes",
{ event: "*", schema: "public", table: "events" },
(payload) => {
setEvents((current) => applyChange(current, payload));
},
)
.subscribe();
// Without this the socket survives navigation and you slowly
// accumulate duplicate subscriptions
return () => {
supabase.removeChannel(channel);
};
}, []);
return <EventTable rows={events} />;
}
That cleanup function is the single most common thing people forget. Every mount opens a channel; without removal, navigating between pages five times leaves you with five live subscriptions all writing to state.
Applying the change
Realtime hands you INSERT, UPDATE, and DELETE with the affected row.
Reducing them into local state is mechanical:
function applyChange(rows: Event[], payload: RealtimePayload<Event>) {
switch (payload.eventType) {
case "INSERT":
return [payload.new, ...rows];
case "UPDATE":
return rows.map((r) => (r.id === payload.new.id ? payload.new : r));
case "DELETE":
return rows.filter((r) => r.id !== payload.old.id);
default:
return rows;
}
}
Keep the sort order consistent with whatever the server used, or rows will jump position the moment one updates.
Row Level Security still applies
Realtime respects RLS. If a policy hides a row from the current user, that user does not receive change events for it either — which is the behaviour you want, but it does mean a subscription that "isn't firing" is often a policy problem rather than a socket problem.
Enable realtime per table explicitly:
alter publication supabase_realtime add table events;
Forgetting this is the other half of "my subscription isn't firing".
When not to use it
Realtime is worth it when updates are genuinely event-driven and the user is watching. For data that changes a few times a day, Next's own revalidation is simpler and costs nothing to run:
export const revalidate = 60;
We use that for the public events page and reserve channels for the admin dashboard, where somebody actually is staring at the screen waiting for a number to move.