Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[realtime database] concurrent queries on the same path don't work #515

Open
monodop opened this issue May 11, 2022 · 2 comments
Open

[realtime database] concurrent queries on the same path don't work #515

monodop opened this issue May 11, 2022 · 2 comments
Assignees

Comments

@monodop
Copy link

monodop commented May 11, 2022

Whenever I have multiple react components that reference the same path (.e.g /users), the library seems to get the results mixed up. In my project, I had a navbar element that displayed an "Admin" button if the user is an admin, and a table that shows all of the users, with some cursor-based pagination. Between those components, only the last query would yield any results. Switching to the second page and back to the first yields zero results, even though the queries passed in are the same (I verified this in the debugger).

As part of my troubleshooting, I tried using get() directly from firebase/database instead of using reactfire, and I had the same issue. This lead me to believe that the root cause comes from firebase-js-sdk instead of reactfire. I found the following issue logged there, but it's been open since February with no fix yet. firebase/firebase-js-sdk#6038

I'm not sure if this should be logged in this project, but it pretty much means this library is completely broken for any real-life applications when using realtime database.

Version info

React: 17.0.2

Firebase: 9.8.1

ReactFire: 4.2.0

Other (e.g. Node, browser, operating system) (if applicable): Chrome 101.0.4951.54

Test case

https://codesandbox.io/s/reactfire-repro-4p16yo

Steps to reproduce

The test case shows that the three queries do not work at the same time. The last loaded table seems to take precedence. If you comment out any of the tables and reload the page, you should be able to see that each query works independently.

I've also seen an issue where sometimes the data doesn't come back at all, but I don't have a repro for that yet.

Expected behavior

Multiple queries on the same page should be able to produce different outputs

Actual behavior

Multiple queries on the same page all produce the same output, or no output at all.

@monodop monodop changed the title [realtime database] concurrent references to the same path doesn't work [realtime database] concurrent queries on the same path don't work May 11, 2022
@jhuleatt
Copy link
Collaborator

Thanks for the detailed report and repro @monodop! Seems like something is up with the code that differentiates Realtime DB queries:

function getUniqueIdForDatabaseQuery(query: DatabaseQuery) {
const index = cachedQueries.findIndex((cachedQuery) => cachedQuery.isEqual(query));
if (index > -1) {
return index;
}
return cachedQueries.push(query) - 1;
}

@jhuleatt jhuleatt self-assigned this May 13, 2022
@felixhayashi
Copy link

Hi, maybe this is issue is now solved via firebase/firebase-js-sdk#6038 (comment)

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

No branches or pull requests

3 participants