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

useSubscriptionQuery() does not update subscription when hook parameters change #524

Open
adamstoffel opened this issue Nov 9, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@adamstoffel
Copy link
Contributor

Describe the bug
useSubscriptionQuery() and useSubscription() setup the Supabase Realtime subscription inside of a useEffect hook with an empty dependencies array.

This means that any change to the parameters passed (e.g. the table name, events, schema, filter, etc.) will NOT cause the actual subscription to be updated and the subscription will continue to notify events only for the first set of parameters passed.

To Reproduce

  1. Setup a subscription with a filter which is derived from a setState variable.
  2. Update the state variable to a new value (e.g. with input field)
  3. Make changes in the DB which should only show up for the old or new filters
  4. See that it always reports changes for the oldest filter param.

Expected behavior
Changes to: channelName, event, schema, table, or filter parameters should cause the subscription to be reset (e.g. unsubscribe and resubscribe).

Additional context
The problem is particularly acute with the usage of filters since this are good use cases for this to be dynamic (e.g. what entity is currently used for active content in the UI). Perhaps only using channelName as the dependency would be sufficient if documentation reflected the necessity of updating channelName when you want

@adamstoffel adamstoffel added the bug Something isn't working label Nov 9, 2024
@psteinroe
Copy link
Owner

Thanks for opening the issue! I like the idea of using the channel name to reset the subscriptions. Would you be willing to contribute this fix and a documentation? 🙏🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants