Supabase Realtime Not Working— Subscriptions Not Firing [Fixed 2026]
Also covers: enable replication · RLS for Realtime · React useEffect cleanup · Broadcast · Presence
⚡ The Symptom
// Subscription set up with no error — but events never fire
const channel = supabase
.channel("posts-changes")
.on("postgres_changes", { event: "*", schema: "public", table: "posts" },
(payload) => {
console.log("Change received!", payload) // never logs
}
)
.subscribe()✅ Step 1 — enable Realtime on the table
# Toggle ON the "posts" table (or whichever table you subscribe to)
# Without this toggle, NO events fire regardless of your subscription codeWhy Supabase Realtime Events Don't Fire
Supabase Realtime works through PostgreSQL's logical replication. For events to be delivered to your client, three things must all be true: Realtime must be enabled for the table in the dashboard, your RLS policies must allow the user to see the rows being changed, and your subscription code must be set up correctly with proper cleanup.
Enable Realtime on the Table
Root cause — Realtime not enabled per tableSupabase does not enable Realtime on all tables by default. You must opt in per table.
# Go to: Database → Replication (in the left sidebar)
# Under "Tables", find your table and toggle it ON
# OR via SQL:
ALTER PUBLICATION supabase_realtime ADD TABLE posts;
# Verify it's enabled:
SELECT schemaname, tablename
FROM pg_publication_tables
WHERE pubname = 'supabase_realtime';You can also enable Realtime when creating a table in the Table Editor by checking the 'Enable Realtime' checkbox. For existing tables, use Database → Replication.
Fix the Subscription Pattern in React
Correct useEffect setup with cleanupSet up the subscription in a useEffect and always return a cleanup function that removes the channel. This prevents memory leaks and duplicate events.
"use client"
import { createClient } from "@/lib/supabase/client"
import { useEffect, useState } from "react"
type Post = { id: string; title: string; created_at: string }
export function useRealtimePosts(initialPosts: Post[]) {
const [posts, setPosts] = useState<Post[]>(initialPosts)
const supabase = createClient()
useEffect(() => {
const channel = supabase
.channel("posts-realtime") // unique channel name
.on(
"postgres_changes",
{
event: "*", // INSERT | UPDATE | DELETE | *
schema: "public",
table: "posts",
// Optional: filter to specific rows
// filter: "user_id=eq.some-uuid",
},
(payload) => {
if (payload.eventType === "INSERT") {
setPosts((prev) => [payload.new as Post, ...prev])
}
if (payload.eventType === "UPDATE") {
setPosts((prev) =>
prev.map((p) => (p.id === payload.new.id ? (payload.new as Post) : p))
)
}
if (payload.eventType === "DELETE") {
setPosts((prev) => prev.filter((p) => p.id !== payload.old.id))
}
}
)
.subscribe((status) => {
console.log("Realtime status:", status) // SUBSCRIBED | CHANNEL_ERROR
})
// ✅ Always return cleanup — prevents duplicate subscriptions
return () => {
supabase.removeChannel(channel)
}
}, [supabase])
return posts
}Fix RLS Blocking Realtime Events
Subscribed but no events — authenticated userSupabase Realtime checks RLS policies before delivering events. If your SELECT policy doesn't cover the changed rows, the event is silently dropped.
-- Allow users to receive Realtime events for their own posts
CREATE POLICY "Users receive realtime for own posts"
ON posts FOR SELECT
USING (auth.uid() = user_id);
-- For public tables — allow anyone to receive Realtime events
CREATE POLICY "Public realtime on posts"
ON posts FOR SELECT
USING (true);
-- Verify your user can SELECT the rows in SQL Editor
SELECT * FROM posts WHERE user_id = 'your-user-uuid-here';
-- If this returns rows, Realtime should work for that userUnsubscribe on Component Unmount
Events firing twice — cleanup not set upIn React Strict Mode (development), effects run twice. Without cleanup, you get two subscriptions and events fire twice. The removeChannel call in the cleanup function prevents this.
useEffect(() => {
const channel = supabase
.channel("my-channel")
.on("postgres_changes", { event: "INSERT", schema: "public", table: "messages" },
(payload) => setMessages((prev) => [...prev, payload.new])
)
.subscribe()
// ✅ This runs when component unmounts OR before effect re-runs
return () => {
supabase.removeChannel(channel)
}
}, []) // empty deps = runs once on mount, cleans up on unmountIf you see events firing twice in development, it is React Strict Mode double-invoking effects — not a bug in your code. In production, effects only run once. The cleanup function handles both cases correctly.
Broadcast and Presence Channels
Real-time messaging, cursors, online usersFor real-time features that don't need database persistence — chat messages, cursor positions, typing indicators, online presence — use Broadcast and Presence instead of postgres_changes.
// Send a message (no database involved)
const channel = supabase.channel("chat-room")
channel
.on("broadcast", { event: "message" }, ({ payload }) => {
console.log("New message:", payload)
setMessages((prev) => [...prev, payload])
})
.subscribe()
// Send from another component/user:
channel.send({
type: "broadcast",
event: "message",
payload: { text: "Hello!", user: "Alice", timestamp: Date.now() },
})const channel = supabase.channel("online-users", {
config: { presence: { key: userId } },
})
channel
.on("presence", { event: "sync" }, () => {
const state = channel.presenceState()
const onlineUsers = Object.keys(state)
setOnlineUsers(onlineUsers)
})
.subscribe(async (status) => {
if (status === "SUBSCRIBED") {
await channel.track({ user_id: userId, online_at: new Date().toISOString() })
}
})Prevention
- Enable Realtime in Dashboard → Database → Replication for every table you subscribe to
- Always add SELECT RLS policies — Realtime checks them before delivering events
- Return supabase.removeChannel(channel) from every useEffect that subscribes
- Use unique channel names per subscription to avoid conflicts
- Log the subscribe() status callback to catch CHANNEL_ERROR during setup
- Use Broadcast for ephemeral real-time data — it doesn't require RLS or table replication
Frequently Asked Questions
Why is my Supabase Realtime subscription not receiving events?+−
How do I enable Supabase Realtime on a table?+−
Do I need to unsubscribe from Supabase Realtime channels?+−
Does Supabase Realtime work with Row Level Security?+−
What is the difference between postgres_changes and Broadcast in Supabase Realtime?+−
Why do I receive Realtime events twice?+−
Need Expert Help?
We Build Real-Time Features with Supabase
Softplix engineers implement Supabase Realtime, Presence, and Broadcast for live dashboards, chat, and collaborative apps. Let us help.
Talk to an Engineer