react-native-onyx 1.0.66 → 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.
@@ -2473,14 +2473,15 @@ function getDisplayName(component) {
2473
2473
  return;
2474
2474
  }
2475
2475
 
2476
- const stateUpdate = { ...this.tempState, loading: false };
2476
+ // Leave untouched previous state to avoid data loss during pre-load updates.
2477
+ // This handles case when setState was called before the setWithOnyxState.
2478
+ // For example, when an Onyx property was updated by keyChanged before the call of the setWithOnyxState.
2479
+ this.setState((prevState) => {
2480
+ const remainingTempState = underscore__WEBPACK_IMPORTED_MODULE_2___default().omit(this.tempState, underscore__WEBPACK_IMPORTED_MODULE_2___default().keys(prevState));
2477
2481
 
2478
- // The state is set here manually, instead of using setState because setState is an async operation, meaning it might execute on the next tick,
2479
- // or at a later point in the microtask queue. That can lead to a race condition where
2480
- // 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.
2481
- this.state = stateUpdate;
2482
+ return { ...remainingTempState, loading: false };
2483
+ });
2482
2484
 
2483
- this.setState(stateUpdate); // Trigger a render
2484
2485
  delete this.tempState;
2485
2486
  }
2486
2487