#8965·rxdb

React useRxDocument starts loading:false; hooks commit stale settled data on key/query change

Author: chris-rnwblCreated Aug 15, 2026Updated Sep 10, 2026
Labelsstale

Bug

1. useRxDocument first paint looks like "not found"

https://github.com/pubkey/rxdb/blob/master/src/plugins/react/hooks/use-rx-document.ts

typescript
const [result, setResult] = useState(null);
const [loading, setLoading] = useState(false); // should be true when a key is set

setLoading(true) runs only in useEffect. The first committed paint is loading: false and result: null. Callers that check loading before treating null as missing still get a false miss on that frame. Going from no key to a key has the same first paint.

#8292 / #8294 set initial loading: true for useRxQuery / useLiveRxQuery only. useRxDocument (#8272) still starts false.

2. Query or key change commits the previous result as settled

On query / primaryKey change, both useLiveRxQuery and useRxDocument keep the previous results / result with loading: false for one committed render. setLoading(true) in useEffect is too late.

Expected

  • useRxDocument: loading is true whenever a key is set and the current key has not emitted yet.
  • After a query or key change, the first committed paint must not present the previous result with loading: false.

Related

  • #8292 / #8294 — initial loading: true for list queries only

Is there a reason or convention behind this behavior? Many other react-hook libraries instead use a pretty aggressive loading: true state before things are resolved. I think Apollo's model is reasonably informative, especially with extended network statuses.