Skip to content

Commit

Permalink
Copy data in updateState instead of moving them
Browse files Browse the repository at this point in the history
Summary:
Changelog: [internal]

`UpdateState` lambda can be called multiple times because of state auto-repeater. But previously we moved state data into the lambda and then moved it into constructor shared data constructor. If auto-repeater called update state lambda again, the data would be in invalid state.
To fix this, state data has to be copied into shared data constructor.

Background executor was more likely to kick trigger state auto-repeater, that's why the crash was happening in BE experiment.
State-autorepeater was enabled at the end of December. That explains why the crash started appearing in v301 (prior to 301, this crash was not happening).

Reviewed By: JoshuaGross, shergin

Differential Revision: D26173800

fbshipit-source-id: 46d1bae226e607d04d5ba28e6c2a8ec86258593a
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Feb 1, 2021
1 parent d6341c4 commit 64d9364
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ReactCommon/react/renderer/core/ConcreteState.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class ConcreteState : public State {
Data &&newData,
EventPriority priority = EventPriority::AsynchronousUnbatched) const {
updateState(
[data = std::move(newData)](Data const &oldData) mutable -> SharedData {
return std::make_shared<Data const>(std::move(data));
[data{std::move(newData)}](Data const &oldData) -> SharedData {
return std::make_shared<Data const>(data);
},
priority);
}
Expand Down

0 comments on commit 64d9364

Please sign in to comment.