© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
12 replies
lewisd

Subscription flickers between SUBSCRIBED and CHANNEL_ERROR?

Every couple of seconds, the subscription will flick between these two states.

I am using
Next.js
Next.js
and supabase version
2rc
2rc
.

Here is my
useEffect
useEffect
:
  useEffect(() => {
    if (!currentUser || conversationIds === null) return;
    const conversationsSubscription = supabase
      .channel(CONVERSATION_MESSAGES_TABLE)
      .on(
        "postgres_changes",
        {
          schema: "public",
          table: CONVERSATION_MESSAGES_TABLE,
          filter: `conversationId=in.(${conversationIds.toString()})`,
          event: "*",
        },
        (payload) => {
          console.log("THIS MESSAGE WAS INSERTED:", payload.new);
          if (payload.eventType === "INSERT") {
            setConversations((existingConversations) => {
              const index = existingConversations.findIndex(
                (conversation) => conversation.id === payload.new.id
              );
              existingConversations[index] = {
                ...existingConversations[index],
                latestMessage: payload.new,
              };
              return existingConversations;
            });
          }
        }
      )
      .subscribe((status) => {
        console.log("THE INBOX SUBSCRIBER IS:", status);
      });
    return () => {
      supabase.removeChannel(conversationsSubscription);
    };
  }, [currentUser, conversationIds, initConversations]);
  useEffect(() => {
    if (!currentUser || conversationIds === null) return;
    const conversationsSubscription = supabase
      .channel(CONVERSATION_MESSAGES_TABLE)
      .on(
        "postgres_changes",
        {
          schema: "public",
          table: CONVERSATION_MESSAGES_TABLE,
          filter: `conversationId=in.(${conversationIds.toString()})`,
          event: "*",
        },
        (payload) => {
          console.log("THIS MESSAGE WAS INSERTED:", payload.new);
          if (payload.eventType === "INSERT") {
            setConversations((existingConversations) => {
              const index = existingConversations.findIndex(
                (conversation) => conversation.id === payload.new.id
              );
              existingConversations[index] = {
                ...existingConversations[index],
                latestMessage: payload.new,
              };
              return existingConversations;
            });
          }
        }
      )
      .subscribe((status) => {
        console.log("THE INBOX SUBSCRIBER IS:", status);
      });
    return () => {
      supabase.removeChannel(conversationsSubscription);
    };
  }, [currentUser, conversationIds, initConversations]);
Screenshot_2022-09-28_at_22.46.59.png
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

How do I debug subscription CHANNEL_ERROR?
SupabaseSSupabase / help-and-questions
4y ago
CHANNEL_ERROR error: mismatch between server and client bindings for postgres changes
SupabaseSSupabase / help-and-questions
3mo ago
realtime subscription error - TS
SupabaseSSupabase / help-and-questions
3y ago
realtime-js channel subscription status is TIMED_OUT
SupabaseSSupabase / help-and-questions
3y ago