Expensify / react-native-onyx

Persistent, offline-first state management solution for React Native. Easy to use with minimal config and boilerplate.
MIT License
160 stars 73 forks source link

Revisit batching of updates with `useOnyx` #571

Open hannojg opened 3 months ago

hannojg commented 3 months ago

In this PR:

We added support for batching updates, so that react only has to commit one big update, instead of updating every component separately. Back then there were only two subscription mechanisms:

Right now, we only batch updates for withOnyx. The reason for that is that in the NewDot code we have a lot of places that do Onyx.connect outside of react and immediately expect data. So we only wanted to batch withOnyx updates, as these were only used with react:

https://github.com/Expensify/react-native-onyx/blob/c53826bbfe31e423fad0c33b0cb9ab097b88f128/lib/OnyxUtils.ts#L1004-L1013

Now we have useOnyx, which internally uses Onyx.connect, not withOnyx. So all components using useOnyx might not be batched.

I opened this issue because I want to look closer, if we need to enable a certain batching logic when using the useOnyx hook.

hannojg commented 3 months ago

Additionally, in fabric, react updates get batched automatically (if concurrent rendering is enabled) - so we might want to see if we can completely get rid of this manual batching mechanism.