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

Race condition - useCollection's add #137

Open
decodeman opened this issue Nov 4, 2021 · 1 comment
Open

Race condition - useCollection's add #137

decodeman opened this issue Nov 4, 2021 · 1 comment

Comments

@decodeman
Copy link

Hi @nandorojo Thanks for the work. In basic use, I think I am seeing my add() call mutate my list properly, but then sometimes (maybe 10-20% of the time) the new record is quickly overlayed by an object like the following where exists is false, etc. I tried a basic collection, no query params even, and the firestore db is fine, the data comes back fine if I refresh my NextJS app, the data and page look fine on mutate... but I am assuming there is a race condition here and don't see how to get around it currently. Help appreciated. Thanks!

exists: false
hasPendingWrites: false
id: "lQR2wuCMg36ykf8GKpw0"
__snapshot: undefined

Note: Subsequent adds may work fine, but the problematic one(s) remain so... until the browser refresh is hit.

@john-zaprite
Copy link

john-zaprite commented Dec 18, 2021

@decodeman Did you ever solve this?

I'm seeing the same issue occurring when directly using mutate on a useDocument query, but on mobile only.

const {
    data,
    update,
    mutate,
    } = useDocument<Invoice>(user?.uid ? `users/${user.uid}/invoices/${invoiceUid}` : null, {
        listen: true,
})

exists: true when page first loads, but then something is changing the snapshot on mobile to become exists: false

A page refresh solves the issue.

Like I said, this only happens on mobile browser (confirmed in live web app and in iOS Simulator locally) .

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

2 participants