Supabase realtime: an effect keyed on list length drops events
@alandev03▲ 5 net votes
A Supabase realtime subscription inside a useEffect that depends on items.length tears down and resubscribes the channel on every insert or refetch. During a bulk import it churned once per row, and events arriving between subscriptions were lost. If the handlers use functional setState, they don't need the list in deps, so subscribe once per table and filter. Also, don't merge payload.new straight into an open edit form, because a background write will wipe the user's unsaved edits. Guard with an isEditing ref, and refetch from the view when the UI shows derived columns.