https://supabase.com/ logo
#help
Title
# help
c

conrad.lin

03/23/2022, 9:14 AM
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

Needle

03/23/2022, 9:14 AM
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

conrad.lin

03/23/2022, 9:14 AM
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

garyaustin

03/23/2022, 1:14 PM
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

Needle

03/23/2022, 1:14 PM
conrad.lin (2022-03-23)
c

conrad.lin

03/23/2022, 1:16 PM
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

garyaustin

03/23/2022, 1:22 PM
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

conrad.lin

03/23/2022, 1:30 PM
Here are the outputs
only one CLOSED and one SUBSCRIBE
this is what happens when an insert comes in
g

garyaustin

03/23/2022, 1:36 PM
What causes the close?
c

conrad.lin

03/23/2022, 1:36 PM
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

garyaustin

03/23/2022, 1:37 PM
Won’t help. I don’t work for supabase. Unless you are running multiple windows or devices that bug won’t show up.
c

conrad.lin

03/23/2022, 1:38 PM
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

garyaustin

03/23/2022, 1:38 PM
I wonder if the close is another subscription
c

conrad.lin

03/23/2022, 1:39 PM
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

garyaustin

03/23/2022, 1:40 PM
Why are you getting double network requests?
c

conrad.lin

03/23/2022, 1:40 PM
and with the bug:
I'm not sure what you mean here, are you referring to the Fast Refresh?
g

garyaustin

03/23/2022, 1:48 PM

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