Subscription flickers between SUBSCRIBED and CHANNEL_ERROR?
Every couple of seconds, the subscription will flick between these two states.
I am using
Here is my
I am using
Next.jsNext.js and supabase version 2rc2rc.Here is my
useEffectuseEffect: 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]);