Hi guys, I've been experiencing an error with real...
# help
c
Hi guys, I've been experiencing an error with realtime and I've been pulling my hair out, I'm thinking its a bug because I can't see anything else I'm doing wrong. I'm using nextjs with supabase. When I run a .subscribe on my database, I've found that it duplicates the response on my front end whenever any action is taken. Currently I'm looking for inserts, and on every single insert, the subscribe function runs twice (and thus triggers twice), causing the code downstream to behave in a funny way.
n
Hello @conrad.lin! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
c
Copy code
const winTracker = await supabase
          .from('success_plan')
          .on('INSERT', (payload) => {
            console.log('New Win Incoming!', payload, payload.new.player);
  
          })
          .subscribe();
This is my code snippet
I'm just not sure if this is a bug or a feature, so if this is supposed to go to github issues, do let me know!
g
There was a bug a week or so ago that would cause a duplicate issue if you were running multiple different users in a certain case. Restart your Supabase instance should make sure you have that fix. The more common case is you are running your subscribe code twice without knowing it.
n
conrad.lin (2022-03-23)
c
Will restart it now and try again. Thank you.
@User thank you for the support, but unfortunately it seems like I am still getting the double notification. If I am running the subscribe code twice, what would be the best way to cancel the other subscribe once it runs again? I tried removeSubscription to no avail.
FYI: following your advice I had isolated the the page with the code running, and ensured it ran only once. Still a problem
I restarted my server with this button. Do let me know if this was correct as well!
g
That is correct
In your subscribe() add this status=>{console.log(status)}. Also you could look in the network tab and see if you have a web socket and in it how many messages from the server.
c
Here are the outputs
only one CLOSED and one SUBSCRIBE
this is what happens when an insert comes in
g
What causes the close?
c
I can DM you my supabase project URL to check if it is upgraded, if that will be helpful?
I'm not exactly sure. The function is called just once to my understanding
g
Won’t help. I don’t work for supabase. Unless you are running multiple windows or devices that bug won’t show up.
c
Gotcha. Thanks so much for helping Gary
To be certain, I only have one window
and one device
running on localhost
for the test
g
I wonder if the close is another subscription
c
I just cleaned it up, got rid of the close
I think just something weird with the refresh, had to restart my server
but still experiencing the same problem as reported earlier
What I get now
g
Why are you getting double network requests?
c
and with the bug:
I'm not sure what you mean here, are you referring to the Fast Refresh?
g

https://media.discordapp.net/attachments/956118681228836894/956184316034048021/unknown.png

These look like select requests to me. Your subscribe code doesn’t use a filter so what are the id=eq. lines