-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Description
When using replicateSupabase to synchronize documents with large text/JSON fields (like HTML content or rich text JSON), the push handler fails with 400 Bad Request errors. The issue occurs because the addDocEqualityToQuery function adds all document fields as equality conditions in the PATCH request URL, causing URL length limits to be exceeded.
Environment
RxDB: 17.0.0-beta.10
Plugin: rxdb/plugins/replication-supabase
Supabase: @supabase/supabase-js latest
Platform: Browser (Chrome/Firefox)
Steps to Reproduce
Create a Supabase table with text/JSON fields that can contain large content (e.g., HTML, rich text)
Set up RxDB collection with matching schema
Configure replicateSupabase with both pull and push enabled
Update a document that has large content fields
Observe the PATCH request in network tab - all fields are included as query params
Replication fails with 400 Bad Request when URL exceeds server limits
Root Cause Analysis
The issue is in addDocEqualityToQuery function (packages/replication-supabase/src/supabase-replication.ts). This function is called during the push handler for updates and adds every field from the assumedMasterState document as a WHERE condition to the PATCH request.
// Simplified view of what happens
let query = supabase
.from('table_name')
.update(updateData);
// This adds ALL fields from assumedMasterState as query parameters
query = addDocEqualityToQuery(assumedMasterState, query);
Expected Behavior
The push handler should generate PATCH requests that:
Use the request body for data, not URL query parameters
Only include necessary fields in WHERE clause for optimistic concurrency (primary key + modified timestamp)
Respect URL length limits (typically 2048-8192 characters)