SupabaseS
Supabase3y ago
bzbz

Inconsistent issues with realtime table

I have two tables in my database that have realtime enabled - a chats table and a notifications table. The chats table seems to work 100% of the time, while the notifications table works maybe 25% of the time. My implementation is very simple:

supabase
.channel('schema-db-changes')
.on(
'postgres_changes',
{
schema: 'public', // Subscribes to the "public" schema in Postgres
event: 'INSERT', // Listen to all changes
table: 'Notifications'
},
(payload) => {
console.log(payload)
const n = [...notifications]
n.push(payload.new as Notifications)
setNotifications(n)
console.log(n)


}
)
.subscribe()

When a new record is inserted, the payload is never being called. I never see the console.log(payload), and in the chrome websocket network debugger, I don't see the event with the row payload (I do see other data, however). When I debug with the realtime listener in the Supabase dashboard, I can see all of the events as they should be with all of the data. Impersonating the account I'm logged into allows me to still see these events, so I know it's not an RLS related issue.

I'm testing this by pulling up two chrome windows, and performing a function in my app on one window that should create a notification in the other. The notification (most of the time) never hits the other window.

The real confusing thing to me is why it sometimes works. The connection never dies according to Chrome. Sometimes I can get it to work by restarting the next.js dev server, but that's hit or miss too lol.

Has anyone else had an issue like this? Is there something I'm overlooking?

Thank you!
Was this page helpful?