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

[BUG] Multiple Filters not Supported by Supabase Realtime #6360

Open
amerryma opened this issue Sep 19, 2024 · 7 comments · May be fixed by #6573
Open

[BUG] Multiple Filters not Supported by Supabase Realtime #6360

amerryma opened this issue Sep 19, 2024 · 7 comments · May be fixed by #6573
Labels
bug Something isn't working good first issue Good for newcomers up for grabs

Comments

@amerryma
Copy link

amerryma commented Sep 19, 2024

Describe the bug

Right now, Supabase Realtime does not support multiple filters. If used, the live provider for supabase will send an invalid filter payload, causing the realtime request to fail.

Steps To Reproduce

  1. Create any realtime resource
  2. Add more than 1 filter to the resource (I was using a useList hook with multiple objects in the filters option)
  3. Watch websocket network requests, it will show an error.

Expected behavior

I think we should either log a warning if we see multiple filters, or naively take the first one?

Packages

  • supabase realtime v2.30.34 (not latest, but also not fixed in latest)
  • @refinedev/supabase 5.9.4

Additional Context

See here for Refine's implementation, where it is joining each filter with a comma.

https://github.com/refinedev/refine/blame/8be95d808ae2f3f280ebd015bd95eb04238fe463/packages/supabase/src/liveProvider/index.ts#L67

See here for feature that is being discussed. No real activity it seems.

supabase/realtime#486
supabase/realtime-js#97

@amerryma amerryma added the bug Something isn't working label Sep 19, 2024
@alicanerdurmaz
Copy link
Member

Hello @amerryma,

Can you please give us the full error log and filters?

@alicanerdurmaz
Copy link
Member

Hello @amerryma, thanks for the issue.

We discussed with the core team and decided not to add filters to the subscription since complex and relation-based filters might not work as expected in Supabase Realtime.

After removing filters, any change in the posts table will trigger the posts query again, ignoring the filters. We believe this approach is correct. What do you think?

@amerryma
Copy link
Author

My workaround for now was picking one filter that did 90% of the server side filtering then did the rest on the client side. So you're saying that you will remove the filtering altogether?

@alicanerdurmaz
Copy link
Member

My workaround for now was picking one filter that did 90% of the server side filtering then did the rest on the client side. So you're saying that you will remove the filtering altogether?

I was wrong. In this use case, the filters must work. We'll investigate this issue and see what we can do.

We're currently considering showing a warning when multiple filters are used and allowing users to override the liveProvider's filters using the meta.realtimeFilters prop.

@amerryma
Copy link
Author

I've also bumped an issue directly inside supabase/realtime to see what the status is there.

@aliemir
Copy link
Member

aliemir commented Oct 10, 2024

Until there are any updates in the supabase side, we should have this working without an error. Picking the first filter will work for many cases but it must be configurable (like meta.realtimeFilter). When working with multiple filters, realtime subscription may log a warning (like @alicanerdurmaz stated) about the current issue and say that only the first filter is picked etc.

If Supabase starts supporting multiple filters in the future, we can just deprecate the realtimeFilter and revert back to the current state 🤔

Maybe @alicanerdurmaz can provide a detailed description for the implementation we want and it will be a guide for anyone interested in working on this issue 🚀 🚀

@alicanerdurmaz
Copy link
Member

alicanerdurmaz commented Oct 15, 2024

@amerryma @aliemir

I think it would be good to warn if there is more than one filter and allow the user to override the filter if needed.

  1. Warning for Multiple Filters
    If more than one filter is used, show a warning to user. If meta.realtimeFilter is available, use that instead of params.filter.
    Code Link

  2. Fix Filter Syntax Errors
    There are some syntax errors in the generated filter. These need to be fixed and tested.

  3. Skip Unsupported Filters
    Some filters that work in Refine don't work with Supabase Realtime. Ignore those filters when generating for Realtime.
    Supabase Realtime Docs

@OmkarBansod02 OmkarBansod02 linked a pull request Dec 11, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers up for grabs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants