Skip to content

Commit

Permalink
Fabric: Fixed a prop application bug in LegacyViewManagerInterop
Browse files Browse the repository at this point in the history
Summary:
The standard merge_patch (aka RFC7386) mechanism that we used before removes the key-value pairs from the original object in case if the patch has a `null` value. And we don't need it there because we should pass this null value down to the mounting layer to clean up this prop there. Besides that, the patch should not be recursive because props are not divisible.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D26435620

fbshipit-source-id: 0d7612c6ca04dcbc122ff6add3777674e3868af8
  • Loading branch information
shergin authored and facebook-github-bot committed Feb 13, 2021
1 parent 1da2369 commit 1e9f63f
Showing 1 changed file with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,34 @@
namespace facebook {
namespace react {

static folly::dynamic recursiveMerge(
folly::dynamic const &lhs,
folly::dynamic const &rhs) {
auto copy = lhs;
copy.merge_patch(rhs);
return copy;
static folly::dynamic mergeRawProps(
folly::dynamic const &source,
folly::dynamic const &patch) {
auto result = source;

if (!result.isObject()) {
result = folly::dynamic::object();
}

if (!patch.isObject()) {
return result;
}

// Note, here we have to preserve sub-prop objects with `null` value as
// an indication for the legacy mounting layer that it needs to clean them up.
for (auto const &pair : patch.items()) {
result[pair.first] = pair.second;
}

return result;
}

LegacyViewManagerInteropViewProps::LegacyViewManagerInteropViewProps(
const LegacyViewManagerInteropViewProps &sourceProps,
const RawProps &rawProps)
: ViewProps(sourceProps, rawProps),
otherProps(
recursiveMerge(sourceProps.otherProps, (folly::dynamic)rawProps)) {}
mergeRawProps(sourceProps.otherProps, (folly::dynamic)rawProps)) {}

} // namespace react
} // namespace facebook

0 comments on commit 1e9f63f

Please sign in to comment.