diff --git a/ReactCommon/fabric/core/propsConversions.h b/ReactCommon/fabric/core/propsConversions.h index f4a25f8dff9e2e..548b88f3de4aa0 100644 --- a/ReactCommon/fabric/core/propsConversions.h +++ b/ReactCommon/fabric/core/propsConversions.h @@ -21,33 +21,49 @@ inline void fromDynamic(const folly::dynamic &value, int &result) { result = val inline void fromDynamic(const folly::dynamic &value, std::string &result) { result = value.getString(); } template -inline T convertRawProp(const RawProps &rawProps, const std::string &name, const T &defaultValue) { +inline T convertRawProp( + const RawProps &rawProps, + const std::string &name, + const T &sourceValue, + const T &defaultValue = T() +) { auto &&iterator = rawProps.find(name); if (iterator == rawProps.end()) { - return defaultValue; + return sourceValue; } auto &&value = iterator->second; + + // Special case: `null` always means `the prop was removed, use default value`. + if (value.isNull()) { + return defaultValue; + } + T result; fromDynamic(value, result); return result; } template -inline static folly::Optional convertRawProp(const RawProps &rawProps, const std::string &name, const folly::Optional &defaultValue) { +inline static folly::Optional convertRawProp( + const RawProps &rawProps, + const std::string &name, + const folly::Optional &sourceValue, + const folly::Optional &defaultValue = {} +) { auto &&iterator = rawProps.find(name); if (iterator == rawProps.end()) { - return defaultValue; + return sourceValue; } auto &&value = iterator->second; - T result; - // Special case for optionals: `null` always means `no value`. + // Special case: `null` always means `the prop was removed, use default value`. if (value.isNull()) { - return {}; + return defaultValue; } + T result; fromDynamic(value, result); return result; }