From c7ec6002f1ce697a2aa37673a72abba498f3dac8 Mon Sep 17 00:00:00 2001 From: empyrical Date: Thu, 10 Sep 2020 10:37:40 -0700 Subject: [PATCH] Fabric: Use std::move on callback in Element::stateData (#29897) Summary: This pull request adds a call to `std::move` on the lambda capture in `Element::stateData`. On Windows/Visual Studio 2017, this fixes a failure in the test `LayoutableShadowNodeTest.contentOriginOffset` where the error `std::bad_function_call` was being thrown. This was narrowed down to the callback being empty when called in `Element::stateData`. https://github.com/facebook/react-native/blob/7e899348c74238a4a042380f86a8fe0d7e05511b/ReactCommon/react/renderer/element/Element.h#L98 Making sure the callback survives with `std::move` allows that test to pass under Windows. ## Changelog Changelog: [Internal][Changed] - Fabric: Use std::move on callback in Element::stateData Pull Request resolved: https://github.com/facebook/react-native/pull/29897 Test Plan: The Fabric test suite passes on Windows after this change is made. I also tested it under macOS and Linux built with Clang and they both pass with this change made. Reviewed By: sammy-SC Differential Revision: D23591969 Pulled By: shergin fbshipit-source-id: e5c88bb0e94641e5128c4d49dd2f9dbfa49e9cfa --- ReactCommon/react/renderer/element/Element.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ReactCommon/react/renderer/element/Element.h b/ReactCommon/react/renderer/element/Element.h index 44ff785ccdb..b6e36a789ef 100644 --- a/ReactCommon/react/renderer/element/Element.h +++ b/ReactCommon/react/renderer/element/Element.h @@ -93,7 +93,8 @@ class Element final { * Sets `state` using callback. */ Element &stateData(std::function callback) { - fragment_.stateCallback = [&]() -> StateData::Shared { + fragment_.stateCallback = [callback = + std::move(callback)]() -> StateData::Shared { auto stateData = ConcreteStateData(); callback(stateData); return std::make_shared(stateData);