SupabaseRealtimeError Fix2026 Updated

Supabase Realtime Not Working— Subscriptions Not Firing [Fixed 2026]

Also covers: enable replication · RLS for Realtime · React useEffect cleanup · Broadcast · Presence

January 20267 min readSupabase Realtime · React · PostgreSQL

⚡ The Symptom

Error
// 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

Supabase Dashboard → Database → Replication
# Toggle ON the "posts" table (or whichever table you subscribe to)
# Without this toggle, NO events fire regardless of your subscription code

Why 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.

1

Enable Realtime on the Table

Root cause — Realtime not enabled per table
1 min

Supabase does not enable Realtime on all tables by default. You must opt in per table.

Supabase Dashboard
# 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.

2

Fix the Subscription Pattern in React

Correct useEffect setup with cleanup
5 min

Set up the subscription in a useEffect and always return a cleanup function that removes the channel. This prevents memory leaks and duplicate events.

hooks/use-realtime-posts.ts
"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
}
3

Fix RLS Blocking Realtime Events

Subscribed but no events — authenticated user
3 min

Supabase Realtime checks RLS policies before delivering events. If your SELECT policy doesn't cover the changed rows, the event is silently dropped.

Add SELECT policy for Realtime
-- 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 user
4

Unsubscribe on Component Unmount

Events firing twice — cleanup not set up
2 min

In 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.

Correct cleanup pattern
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 unmount

If 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.

5

Broadcast and Presence Channels

Real-time messaging, cursors, online users
5 min

For 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.

Broadcast — send messages between clients
// 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() },
})
Presence — track who is online
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

Frequently Asked Questions

Why is my Supabase Realtime subscription not receiving events?+
The two most common causes are: 1) Realtime is not enabled for the specific table in Supabase Dashboard — you must enable it per table under Database → Replication. 2) Your RLS policies block Realtime — add a SELECT policy on the table so the Realtime server can deliver events to authenticated users.
How do I enable Supabase Realtime on a table?+
Go to Supabase Dashboard → Database → Replication → Tables. Toggle on the table you want to listen to. Without this, no Realtime events will fire for that table regardless of your subscription code.
Do I need to unsubscribe from Supabase Realtime channels?+
Yes. Always call supabase.removeChannel(channel) when your component unmounts (React useEffect cleanup function). Not unsubscribing causes memory leaks and duplicate event handlers when components re-mount, leading to events firing multiple times.
Does Supabase Realtime work with Row Level Security?+
Yes, but you need to ensure your RLS SELECT policies allow the authenticated user to read the rows. Realtime uses the user's JWT to check RLS — if the user can't SELECT the row, they won't receive Realtime events for it.
What is the difference between postgres_changes and Broadcast in Supabase Realtime?+
postgres_changes listens to INSERT, UPDATE, and DELETE events on a database table — data changes. Broadcast lets clients send arbitrary messages to each other through a channel without hitting the database — useful for presence, cursors, or game state. Presence tracks which users are currently online in a channel.
Why do I receive Realtime events twice?+
Duplicate events usually happen because the useEffect that sets up the subscription runs more than once (React Strict Mode double-invokes effects in development) and the cleanup function doesn't properly unsubscribe. Ensure you return the removeChannel call from useEffect.

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