supabase-cache-helpers icon indicating copy to clipboard operation
supabase-cache-helpers copied to clipboard

What is the meaning of "Channel names must be unique when using multiple subscription hooks"?

Open jameshfisher opened this issue 11 months ago • 2 comments

On this page I read:

NOTE: Channel names must be unique when using multiple subscription hooks.

What does "uniqueness" mean here? Some possible interpretations:

  • It's an error for my code to have two useSubscription call sites using the same channel name
  • It's an error for a client to call useSubscription twice using the same channel name
  • It's an error for two separate clients to try to subscribe using the same channel name

I don't know how to interpret this advice, because I have no mental model of how channel names are used in this Postgres changes system, and haven't been able to find any model in the Supabase docs. (I've asked about this on their Discord support.)

Whatever the meaning is, what is the consequence of not using unique channel names? What bad things can happen?

Thanks again for this library! <3

jameshfisher avatar Mar 04 '24 13:03 jameshfisher

Or - what if I just use Math.random().toString() in my channel name, so it's unique every time the hook is called?

jameshfisher avatar Mar 04 '24 13:03 jameshfisher

hey! thanks for the kind words.

I don't know how to interpret this advice, because I have no mental model of how channel names are used in this Postgres changes system, and haven't been able to find any model in the Supabase docs. (I've asked about this on their Discord support.)

I actually also do not know exactly how the channel names work. I used this with both a static string, e.g. conversations when subscribing the conversation table, and one that includes the table and the filter, e.g. conversations:inbox-${inboxId}. Both work fine.

psteinroe avatar Mar 04 '24 13:03 psteinroe