Skip to content

fix(live): resolve variable shadowing in unsubscribe callback filtering#1051

Open
Nyx-abu wants to merge 1 commit into
electric-sql:mainfrom
Nyx-abu:fix-live-unsubscribe-shadowing
Open

fix(live): resolve variable shadowing in unsubscribe callback filtering#1051
Nyx-abu wants to merge 1 commit into
electric-sql:mainfrom
Nyx-abu:fix-live-unsubscribe-shadowing

Conversation

@Nyx-abu

@Nyx-abu Nyx-abu commented Jul 12, 2026

Copy link
Copy Markdown

Hi team,

I found a bug in the live query unsubscribe logic where trying to remove a specific listener actually drops all subscribed callbacks.

The Bug

In packages/pglite/src/live/index.ts, the inner variable in the ilter function shadows the outer callback parameter:
ypescript callbacks = callbacks.filter((callback) => callback !== callback)
Because of the shadowing, it checks if the callback is not equal to itself, which always evaluates to alse. As a result, the ilter() returns an empty array, and all live query listeners are wiped out whenever a single unsubscription occurs.

The Fix

I simply renamed the inner variable to cb in the three places this occurs:
ypescript callbacks = callbacks.filter((cb) => cb !== callback)

This ensures the filter correctly identifies and removes only the intended listener while preserving the others. Let me know if you need any adjustments!

The inner filter parameter 'callback' shadowed the outer 'callback' argument in the unsubscribe functions. This caused 'callback !== callback' to always evaluate to false, meaning all callbacks were inadvertently unsubscribed when attempting to remove a single listener. Changing the inner parameter to 'cb' correctly preserves the other active listeners.
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.

1 participant