Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot have multiple subscriptions on same table #271

Closed
leandertolksdorf opened this issue Mar 30, 2022 · 1 comment
Closed

Cannot have multiple subscriptions on same table #271

leandertolksdorf opened this issue Mar 30, 2022 · 1 comment
Assignees
Labels
bug Something isn't working realtime wontfix This will not be worked on

Comments

@leandertolksdorf
Copy link

NOTE: This is a duplicate of #246 because I'm not sure to which repository this actually belongs.

Bug report

Describe the bug

I have two independent React components from which I create supabase realtime subscriptions like this:

useEffect(() => {
  const subscription = supabase
    .from<definitions["customer"]>("customer")
    .on("*", () => console.log("change"))
    .subscribe();
  return () => supabase.removeSubscription(subscription);
});

When having both components in one page, one of the subscriptions doesn't fire on changing a row.

When changing the "*" in both components to differ from each other, for example

Component 1: "INSERT"
Component 2: "UPDATE",

logging of supabase.getSubscriptions() shows that only one of them is present in bindings.

I assume the first loaded subscription is replaced with the second loaded when calling subscribe() again, and I'm not sure if this really is a bug or intended.

To Reproduce

  1. Create two separate realtime subscriptions on the same table
  2. After creating both, log supabase.getSubscriptions(). Only one will be present.
  3. Have them both load on one page
  4. Change anything in the DB and observe which subscription reacts to the change.

Expected behavior

Both callbacks are run on DB change.

@leandertolksdorf leandertolksdorf added the bug Something isn't working label Mar 30, 2022
@monicakh monicakh transferred this issue from supabase/supabase-js Aug 3, 2022
@w3b6x9
Copy link
Member

w3b6x9 commented Aug 6, 2022

@leandertolksdorf this is intended. When you do .on("*") you're essentially listening to the following topic realtime:*. Currently, Realtime only allows listening to unique topics per socket connection.

@w3b6x9 w3b6x9 closed this as completed Aug 6, 2022
w3b6x9 pushed a commit that referenced this issue Nov 4, 2022
move assignment of DB_ENC_KEY to runtime.ex
carlobeltrame added a commit to gloggi/tramopoly that referenced this issue Feb 1, 2023
…el fetches

Supabase realtime has an undocumented limitation that the subscription
channel name must be unique. supabase/realtime#271
It is very badly documented, but the channel name can actually be any
string. So we can fix this by using the store name for the subscription
channel.

Fixing this resulted in more distinct subscriptions, so I had to put some
effort into reducing this number back down to the minimum.
If a store is already subscribed, we don't have to subscribe again. This
was especially important for the abteilungen store, which is
re-subscribed every time the group scores change (I think because of the
group ranking).

Also, force reloading should still not cause overlapping duplicate
requests. The forceReload flag should just affect the case when there is
already data present in the store.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working realtime wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants