fix: supabase Realtime subscription to handle only the first filter #7201
+22
−13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue:
Supabase Realtime currently supports only one filter per subscription. When multiple filters were provided, the live provider would send an invalid payload, causing the subscription to fail.
Fix:
Updated liveProvider in packages/supabase/src/liveProvider/index.ts.
Added mapFilter function to handle multiple filters by using only the first filter.
Added a console warning to inform users when multiple filters are provided.
Ensures that the filter parameter in Supabase Realtime is valid, preventing subscription errors.
Changes in this PR:
mapFilter function added to safely map filters.
Subscriptions now correctly apply only the first filter.
Console warning added for clarity.
All other functionality of liveProvider remains intact.
Example:
// Before: multiple filters would break subscription
subscribe({
channel: "resources/posts",
types: ["created", "updated"],
params: {
filters: [
{ field: "status", operator: "eq", value: "active" },
{ field: "category", operator: "eq", value: "tech" },
],
},
callback: () => {},
});
// After: only first filter is applied, subscription works
Testing:
Manual testing on local Supabase project confirmed that multiple filters no longer break the subscription.
Verified that single filters still work as expected.
Checked console warning appears when more than one filter is passed.
Related Issue:
(If the repo has an issue number, add it here, e.g., Fixes #1234)
Impact:
Improves stability for users subscribing with filters in Supabase Realtime.
Avoids runtime errors due to unsupported multiple filters.