Replies: 5 comments
-
I think this is the behavior of the underlying Firestore SDK, and not ReactFire-specific. If it is, since you're using But let's leave this open in case it is a ReactFire bug |
Beta Was this translation helpful? Give feedback.
-
I don't think it's a bug per se. But I don't think I could get the behavior I want with a simple wrapper function, since I want it to remain suspended until a non-cached snapshot appears. I hope I'm wrong? My thinking was that there could be an option you could pass to |
Beta Was this translation helpful? Give feedback.
-
I've confirmed that this is the behavior of the Firestore SDK itself. I wonder if we update
If you want to write your own implementation of import {useObservable} from 'reactfire';
// import other stuff...
export function useFirestoreCollectionButSkipCache<T = { [key: string]: unknown }>(
query: firestore.Query,
options?: ReactFireOptions<T[]>
): T extends {} ? T[] : firestore.QuerySnapshot {
const queryId = getHashFromFirestoreQuery(query);
return useObservable(
fromCollectionRef(query, checkIdField(options)).pipe(skipWhile(snap => snap.metadata.fromCache)),
queryId,
options ? options.startWithValue : undefined
);
} |
Beta Was this translation helpful? Give feedback.
-
That's an interesting idea! It would probably have to be serialised, somehow, so that different operators create different |
Beta Was this translation helpful? Give feedback.
-
I think this use case is a good example to add to the advanced usage docs |
Beta Was this translation helpful? Give feedback.
-
This little example demonstrates an, in my opinion, unfortunate behavior.
Story time: I had a component that was supposed to show a list of documents, and progressively load more documents as the user scrolls. I did the obvious thing and made a limited query, and had the limit in a state. But when I changed this state, the component didn't suspend until the results arrived like I expected, rather it switched momentarily to only showing a single document. Turns out this was because I had subscribed to that particular document from a different component.
I understand if you don't want to make it the default behavior to suspend until the first non-cache response arrives, but there must be some sort of middle ground.
Beta Was this translation helpful? Give feedback.
All reactions