Subscription flickers between SUBSCRIBED and CHANNEL_ERROR?

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

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

Here is my
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]);
Screenshot_2022-09-28_at_22.46.59.png
Was this page helpful?