Skip to content

bug(query): promiseEvents with 'once' not working after logout/relogin #436

Open
@matt-way

Description

@matt-way

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

In my app, I use promiseEvents with once directly to check if a particular value exists in the database before performing some logic. Like:

return firebase.promiseEvents([{
  type: 'once', path: `Event/${eventId}`
}]).then(() => {
  // check the state for the object

This works fine, except when i logout and then log back in. I have walked through the code, and the problem is in the watchEvent function here:

const id = queryId || getQueryIdFromPath(path)
const counter = getWatcherCount(firebase, type, watchPath, id)

if (counter > 0) {
  if (id) {
    unsetWatcher(firebase, dispatch, type, path, id)
  } else {
    return
  }
}  

It appears that the watch still exists even after logging out, and there is an issue with the id system figuring out how to unset the watcher. I believe it is because of a difference between getQueryIdFromPath and getWatcherCount

These two lines:

In watchEvent
const id = queryId || getQueryIdFromPath(path) &
In getWatcherCount
var id = queryId || getQueryIdFromPath(path, event) || getWatchPath(event, path)

Now I can fix the problem, by using this call instead, and directly setting the query id:

return firebase.promiseEvents([{
  type: 'once', path: `Event/${eventId}`,
  queryId: `once:/Event/${eventId}`
}]).then(() => {

What is the expected behavior?

Unless I have missed a better (proper) way to do all of this, I don't think you should have to be explicit about the vague queryId, and that logout is able to clear all the watchers.

Which versions of dependencies, and which browser and OS are affected by this issue? Did this work in previous versions or setups?

v2.0.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions