fix(live): resolve variable shadowing in unsubscribe callback filtering#1051
Open
Nyx-abu wants to merge 1 commit into
Open
fix(live): resolve variable shadowing in unsubscribe callback filtering#1051Nyx-abu wants to merge 1 commit into
Nyx-abu wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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!