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

fix: improve Supabase liveProvider filter handling #6573

Open
wants to merge 10 commits into
base: next
Choose a base branch
from

Conversation

OmkarBansod02
Copy link
Contributor

@OmkarBansod02 OmkarBansod02 commented Dec 11, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

Supabase Realtime doesn't support multiple filters, causing errors in requests when more than one filter is used.

What is the new behavior?

Supabase Realtime handles one filter at a time, logs a warning for multiple filters, and allows overriding the filter with meta.realtimeFilter for more control.

fixes #6360

Notes for reviewers

I’ve made the changes as discussed in the issue and added support for handling single filters in the Supabase liveProvider. Please take a look at the implementation and let me know if any further adjustments are needed.

@OmkarBansod02 OmkarBansod02 requested a review from a team as a code owner December 11, 2024 17:27
Copy link

changeset-bot bot commented Dec 11, 2024

🦋 Changeset detected

Latest commit: 19d371f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@refinedev/supabase Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Dec 11, 2024

Deploy Preview for refine-doc-live-previews ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 6600f6b
🔍 Latest deploy log https://app.netlify.com/sites/refine-doc-live-previews/deploys/675c471c68fa130008993095
😎 Deploy Preview https://deploy-preview-6573--refine-doc-live-previews.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

.changeset/shiny-panthers-nail.md Outdated Show resolved Hide resolved
.changeset/shiny-panthers-nail.md Outdated Show resolved Hide resolved
@BatuhanW BatuhanW added this to the January 2025 🎄 milestone Dec 17, 2024
@BatuhanW BatuhanW changed the base branch from main to next December 17, 2024 12:53
Copy link
Member

@BatuhanW BatuhanW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @OmkarBansod02 thanks for the updates. Did you test this one locally? Would be nice to have a screen recording with devtools enabled to see if this works as expected.

@OmkarBansod02
Copy link
Contributor Author

Hey @BatuhanW , I have tested the changes from the PR locally, and it appears to be working fine. Below are the screen recordings demonstrating the behavior with both a single filter and multiple filters:

  • Single Filter:
single.filter.mp4
  • Multiple Filters:
multiple.Filters.mp4

In the case of multiple filters, as expected, the system logs a warning and uses only the first filter. This matches the intended behavior outlined in the PR.

However, I didn't observe the WebSocket error mentioned in the issue description it's possible I may have missed something.
but from what I have observed, the changes implemented in this PR appear to be functioning correctly.

Please take a look and let me know if there are any other scenarios I should test.

Copy link
Member

@BatuhanW BatuhanW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @OmkarBansod02

Copy link
Member

@aliemir aliemir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for PR @OmkarBansod02, left couple of comments.

@@ -7,6 +7,8 @@ import type {
import { liveTypes, supabaseTypes } from "../types";
import { mapOperator } from "../utils";

const supportedOperators = ["eq", "neq", "gt", "lt", "gte", "lte"];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"neq" is not a valid operator in Refine. We use "ne" instead. Please check mapOperator utility to confirm. This variable can have CrudFilters[] type defined for safety.

Comment on lines 63 to 65
console.warn(
"Warning: Multiple filters detected. Supabase Realtime currently supports only a single filter. The first filter will be applied. To customize this behavior, use the 'meta.realtimeFilter' property.",
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This always logs a warning even if meta.realtimeFilter is set.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider using warn-once with a proper key (resource can be used) to prevent polluting user console.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've implemented warnOnce for the multiple filter warning and tested it locally. Here's a screen recording of the behavior, let me know if this aligns with what you were expecting!

Screen.Recording.2025-01-01.231040.mp4

fix: handle multiple filters in Supabase liveProvider.
This update addresses the handling of multiple filters in the Supabase liveProvider. It ensures only the first filter is applied and introduces a configurable `meta.realtimeFilter` option for custom filter behavior. A warning is logged when multiple filters are detected.

Resolves [#6360](https://github.com/refinedev/refine/issues/6360)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Resolves [#6360](https://github.com/refinedev/refine/issues/6360)
[Resolves #6360](https://github.com/refinedev/refine/issues/6360)

if ("field" in filter) {
if (
"field" in filter &&
supportedOperators.includes(filter.operator)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs to be logged if unsupported filters are used.

@OmkarBansod02
Copy link
Contributor Author

hey @aliemir I’ve made the changes you suggested in the comments and tested them locally. Let me know if this meets your expectations or if any further changes are required!

Screen.Recording.2025-01-02.135941.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Multiple Filters not Supported by Supabase Realtime
3 participants