Skip to content

returned values from useDocument and useCollection using a getter aren't reactive #1495

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

Closed
ralacerda opened this issue Feb 20, 2024 · 1 comment · Fixed by #1496
Closed
Labels

Comments

@ralacerda
Copy link
Contributor

ralacerda commented Feb 20, 2024

Reproduction

https://stackblitz.com/edit/vitejs-vite-wlriny?file=src%2FApp.vue

Steps to reproduce the bug

The reproduction example show ways to use useDocument and useCollection

const userDocumentComputed = useDocument(
  computed(() => {
    return currentUser.value ? doc(db, 'users', currentUser.value.uid) : null;
  })
);

const userDocument = useDocument(() => {
  return currentUser.value ? doc(db, 'users', currentUser.value.uid) : null;
});

const userFriends = useCollection(() => {
  return currentUser.value
    ? collection(db, 'users', currentUser.value.uid, 'friends')
    : null;
});

const userFriendsComputed = useCollection(
  computed(() => {
    return currentUser.value
      ? collection(db, 'users', currentUser.value.uid, 'friends')
      : null;
  })
);
  • Login as a user
  • Noticed how the data coming from a function won't change to the correct values, but data coming from computed will
  • Logout and login as another user

Expected behavior

Acording to the documentation, you can pass both a getter or a computed().
https://vuefire.vuejs.org/guide/realtime-data.html#Declarative-realtime-data.
So userDocument and userFriends should update when you change user

Actual behavior

refs that were created by using an getter are not reactive (userDocument and userFriends )

Additional information

This looks like a bug as the documentation show the usage of a getter.

Either way, I'm willing to dive into the source code to understand/fix the bug, or to update the documentation to make it clear that getters aren't supported.

@ralacerda ralacerda changed the title Using a getter for useCollection and useDocs won't work returned values from useDocument and useCollection using a getter aren't reactive Feb 20, 2024
@posva posva added the bug label Feb 21, 2024
@posva
Copy link
Member

posva commented Feb 21, 2024

This should indeed work. I'm happy you want to contribute! The bug should be the usage of isRef() in order to setup the watcher in both firestore and database. Could you add a test too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants