FirebaseExtended / reactfire

Hooks, Context Providers, and Components that make it easy to interact with Firebase.
https://firebaseopensource.com/projects/firebaseextended/reactfire/
MIT License
3.52k stars 401 forks source link

Make sure Firestore hooks return `undefined` when data does not exist #446

Closed jhuleatt closed 3 years ago

jhuleatt commented 3 years ago

fixes #440

jhuleatt commented 3 years ago

Turns out this is an issue with useObservable itself. The internal state of useObservable starts off with the data as undefined, so when undefined is emitted as the new data, the hook doesn't trigger a rerender, because from React's perspective nothing changed.

Reproduced with failing test "useObservable > Non-Suspense Mode > emits even if data is undefined"

jhuleatt commented 3 years ago

I'm going to admin-merge this because #438 is a pretty active discussion so a fast fix would be beneficial, I was able to repro the original issue with a test that is now green, and useObservable has pretty solid test coverage.