realtime-and-subscriptions
Skill10 starsChanged 6 months agoMITView on GitHub
Use when adding Supabase Realtime, live updates, chat, notifications, or postgres_changes subscriptions. Not for one-time fetches (use data hooks) or polling unless Realtime is unavailable.
In this repository56 other files it gives its agents.
- accessibility-passSkill
- analytics-eventsSkill
- api-error-handlingSkill
- audit-logging-backendSkill
- background-jobs-and-cronSkill
- dark-mode-and-themingSkill
- dashboard-charts-rechartsSkill
- edge-functions-and-webhooksSkill
- email-and-notificationsSkill
- error-states-and-empty-uiSkill
- feature-flags-and-togglesSkill
- file-upload-storageSkill
- i18n-multi-languageSkill
- lovable-prompting-playbookSkill
- lovable-ship-checklistSkill
- migration-playbookSkill
- multi-tenant-backendSkill
- onboarding-copySkill
- optimistic-updatesSkill
- payment-failed-and-recoverySkill
- payment-webhook-idempotencySkill
- payment-webhook-testingSkill
- performance-budgetSkill
- pg-cron-recipesSkill
- pg-cron-scheduled-jobsSkill
- pg-cron-with-pg-net-edgeSkill
- postgres-full-text-searchSkill
- postgres-triggers-and-functionsSkill
- pricing-and-billingSkill
- programmatic-seo-content-qualitySkill
- programmatic-seo-pagesSkill
- rate-limiting-edgeSkill
- refactor-safe-diffSkill
- release-notesSkill
- seo-core-web-vitalsSkill
- seo-landing-pageSkill
- seo-meta-tags-spaSkill
- seo-sitemap-generationSkill
- seo-ssr-and-prerenderingSkill
- seo-structured-dataSkill
- server-input-validationSkill
- shadcn-patternsSkill
- soft-delete-and-archivingSkill
- stripe-one-time-payment-webhooksSkill
- stripe-payment-webhooksSkill
- supabase-auth-flowsSkill
- supabase-database-designSkill
- supabase-rls-and-authSkill
- support-replySkill
- tanstack-infinite-queriesSkill
- tanstack-mutations-and-invalidationSkill
- tanstack-prefetch-and-hydrationSkill
- tanstack-query-alternativeSkill
- tanstack-router-data-loadersSkill
- tanstack-start-server-routesSkill
- typed-api-hooks-formsSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 11
Use Supabase Realtime for live data.
- Very specific: line 44
Prefer narrow filters (filter: \room_id=eq.${id}\``) over subscribing to whole tables.
- Very specific: line 50
Use channel.on("presence", ...) or broadcast only when product requires it.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Realtime and subscriptions
Use Supabase Realtime for live data; pair with existing query cache (SWR/React Query) for initial load.
Setup
- Enable Realtime on the table in Supabase (publication / replica identity as required).
- RLS must allow the subscriber to
SELECTrows they receive.
Subscription pattern
useEffect(() => {
if (!channelId) return;
const channel = supabase
.channel(`room:${channelId}`)
.on(
"postgres_changes",
{ event: "*", schema: "public", table: "messages", filter: `room_id=eq.${channelId}` },
(payload) => {
// merge into local state or call mutate() on SWR/React Query key
}
)
.subscribe();
return () => {
supabase.removeChannel(channel);
};
}, [channelId]);Rules
- Always unsubscribe on unmount (
removeChannel). - Prefer narrow filters (
filter: \room_id=eq.${id}``) over subscribing to whole tables. - On
INSERT/UPDATE/DELETE, update cache viamutate/queryClient.setQueryData— avoid full refetch storms. - Show connection status if UX needs it (optional reconnect banner).
Presence / broadcast (chat typing)
Use channel.on("presence", ...) or broadcast only when product requires it; keep payloads small.
Reconnect and offline
- Supabase Realtime auto-reconnects, but stale state is your problem: on
SUBSCRIBEDafter a disconnect, refetch the initial query so missed events are reconciled.
.subscribe((status) => {
if (status === "SUBSCRIBED") refetch();
});- Optionally show a small "Reconnecting…" indicator if the channel disconnects.
Avoid
- Leaving channels open after navigation away.
- Subscribing without RLS (leaks data).
- Duplicating Realtime + 1s polling for the same data.
- Subscribing to high-traffic tables without a filter.
Checklist
- Cleanup in
useEffectreturn. - RLS verified for subscribed rows.
- Cache stays consistent with hook layer.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

