react-native-onyx 1.0.67 → 1.0.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/withOnyx.js CHANGED
@@ -132,14 +132,15 @@ export default function (mapOnyxToState) {
132
132
  return;
133
133
  }
134
134
 
135
- const stateUpdate = {...this.tempState, loading: false};
135
+ // Leave untouched previous state to avoid data loss during pre-load updates.
136
+ // This handles case when setState was called before the setWithOnyxState.
137
+ // For example, when an Onyx property was updated by keyChanged before the call of the setWithOnyxState.
138
+ this.setState((prevState) => {
139
+ const remainingTempState = _.omit(this.tempState, _.keys(prevState));
136
140
 
137
- // The state is set here manually, instead of using setState because setState is an async operation, meaning it might execute on the next tick,
138
- // or at a later point in the microtask queue. That can lead to a race condition where
139
- // setWithOnyxState is called before the state is actually set. This results in unreliable behavior when checking the loading state and has been mainly observed on fabric.
140
- this.state = stateUpdate;
141
+ return ({...remainingTempState, loading: false});
142
+ });
141
143
 
142
- this.setState(stateUpdate); // Trigger a render
143
144
  delete this.tempState;
144
145
  }
145
146
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "1.0.67",
3
+ "version": "1.0.68",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",