geofire-js icon indicating copy to clipboard operation
geofire-js copied to clipboard

wrap off(firebaseQuery, 'value', valueUnsubscribe) in setTimeout-0

Open tobias74 opened this issue 1 year ago • 1 comments

Description

In some cases (especially when frequently subscribing and unsubscribing geo queries) there was an error:

Uncaught ReferenceError: Cannot access 'valueUnsubscribe' before initialization at GeoQuery.ts:485:37

It seems that in those cases the callback provided to onValue was called synchronously before returning valueUnsubscribe from the function call. Therefore valueUnsubscribe was not yet fully defined (Temporal Dead Zone ?)

tobias74 avatar Oct 26 '24 14:10 tobias74

I have just looked into the docs for onValue: it returns an unsubscribe function. So my question is: Does this implementation:

off(firebaseQuery, 'value', valueUnsubscribe);

really unsubscribe correctly? Shouldn't it just be:

valueUnsubscribe();

tobias74 avatar Oct 26 '24 15:10 tobias74