Skip to content

Commit

Permalink
Clean up fastAddProperties and make it more correct (#29015)
Browse files Browse the repository at this point in the history
## Summary

This PR makes some fixes to the `fastAddProperties` function:
- Use `if (!attributeConfig)` instead of `if (attributeConfig ===
undefined)` to account for `null`.
- If a prop has an Object `attributeConfig` with a `diff` function
defined on it, treat it as an atomic value to keep the semantics of
`diffProperties`.

## How did you test this change?

Build and run RNTester app.

DiffTrain build for commit b37e4b4.
  • Loading branch information
dmytrorykun committed May 8, 2024
1 parent acdffc0 commit 34748be
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
703983426243422d9726ca3a0c7eef54e173a6bb
b37e4b4e616d6d66c1cde9c0a4c2cbd866b0b582
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<854ee92767fe1d880e62f5cc7c83d537>>
* @generated SignedSource<<577c7636235832d840ad016860b50817>>
*/

'use strict';
Expand Down Expand Up @@ -2350,57 +2350,63 @@ function diffProperties(updatePayload, prevProps, nextProps, validAttributes) {
return updatePayload;
}

function fastAddProperties(updatePayload, nextProps, validAttributes) {
function fastAddProperties(payload, props, validAttributes) {
var attributeConfig;
var nextProp;
var prop;

for (var propKey in nextProps) {
nextProp = nextProps[propKey];
for (var propKey in props) {
prop = props[propKey];

if (nextProp === undefined) {
if (prop === undefined) {
continue;
}

attributeConfig = validAttributes[propKey];

if (attributeConfig === undefined) {
if (attributeConfig == null) {
continue;
}

if (typeof nextProp === 'function') {
nextProp = true;
}

if (typeof attributeConfig !== 'object') {
if (!updatePayload) {
updatePayload = {};
}
var newValue = void 0;

updatePayload[propKey] = nextProp;
continue;
if (typeof prop === 'function') {
// A function prop. It represents an event handler. Pass it to native as 'true'.
newValue = true;
} else if (typeof attributeConfig !== 'object') {
// An atomic prop. Doesn't need to be flattened.
newValue = prop;
} else if (typeof attributeConfig.process === 'function') {
// An atomic prop with custom processing.
newValue = attributeConfig.process(prop);
} else if (typeof attributeConfig.diff === 'function') {
// An atomic prop with custom diffing. We don't do diffing here.
newValue = prop;
}

if (typeof attributeConfig.process === 'function') {
if (!updatePayload) {
updatePayload = {};
if (newValue !== undefined) {
if (!payload) {
payload = {};
}

updatePayload[propKey] = attributeConfig.process(nextProp);
payload[propKey] = newValue;
continue;
}
} // Not-atomic prop that needs to be flattened. Likely it's the 'style' prop.
// It can be an array.


if (isArray(nextProp)) {
for (var i = 0; i < nextProp.length; i++) {
updatePayload = fastAddProperties(updatePayload, nextProp[i], attributeConfig);
if (isArray(prop)) {
for (var i = 0; i < prop.length; i++) {
payload = fastAddProperties(payload, prop[i], attributeConfig);
}

continue;
}
} // Or it can be an object.


updatePayload = fastAddProperties(updatePayload, nextProp, attributeConfig);
payload = fastAddProperties(payload, prop, attributeConfig);
}

return updatePayload;
return payload;
}
/**
* addProperties adds all the valid props to the payload after being processed.
Expand Down Expand Up @@ -26089,7 +26095,7 @@ identifierPrefix, onUncaughtError, onCaughtError, onRecoverableError, transition
return root;
}

var ReactVersion = '19.0.0-beta-bf4ea329';
var ReactVersion = '19.0.0-beta-83bc2843';

/*
* The `'' + value` pattern (used in perf-sensitive code) throws for Symbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<4d85e00114107b7747eb3de320972dc1>>
* @generated SignedSource<<844a7fde793a6bcbd87492fec25685e4>>
*/

"use strict";
Expand Down Expand Up @@ -1200,38 +1200,35 @@ function diffProperties(updatePayload, prevProps, nextProps, validAttributes) {
)))));
return updatePayload;
}
function fastAddProperties(updatePayload, nextProps, validAttributes) {
function fastAddProperties(payload, props, validAttributes) {
var propKey;
for (propKey in nextProps) {
var nextProp = nextProps[propKey];
if (void 0 !== nextProp) {
for (propKey in props) {
var prop = props[propKey];
if (void 0 !== prop) {
var attributeConfig = validAttributes[propKey];
if (void 0 !== attributeConfig)
if (
("function" === typeof nextProp && (nextProp = !0),
"object" !== typeof attributeConfig)
)
updatePayload || (updatePayload = {}),
(updatePayload[propKey] = nextProp);
else if ("function" === typeof attributeConfig.process)
updatePayload || (updatePayload = {}),
(updatePayload[propKey] = attributeConfig.process(nextProp));
else if (isArrayImpl(nextProp))
for (var i = 0; i < nextProp.length; i++)
updatePayload = fastAddProperties(
updatePayload,
nextProp[i],
if (null != attributeConfig) {
var newValue = void 0;
"function" === typeof prop
? (newValue = !0)
: "object" !== typeof attributeConfig
? (newValue = prop)
: "function" === typeof attributeConfig.process
? (newValue = attributeConfig.process(prop))
: "function" === typeof attributeConfig.diff && (newValue = prop);
if (void 0 !== newValue)
payload || (payload = {}), (payload[propKey] = newValue);
else if (isArrayImpl(prop))
for (newValue = 0; newValue < prop.length; newValue++)
payload = fastAddProperties(
payload,
prop[newValue],
attributeConfig
);
else
updatePayload = fastAddProperties(
updatePayload,
nextProp,
attributeConfig
);
else payload = fastAddProperties(payload, prop, attributeConfig);
}
}
}
return updatePayload;
return payload;
}
function addProperties(updatePayload, props, validAttributes) {
return enableAddPropertiesFastPath
Expand Down Expand Up @@ -10592,7 +10589,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1124 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "19.0.0-beta-8abbffa0",
version: "19.0.0-beta-bdce1f91",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
Expand Down Expand Up @@ -10635,7 +10632,7 @@ var internals$jscomp$inline_1356 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-beta-8abbffa0"
reconcilerVersion: "19.0.0-beta-bdce1f91"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1357 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<3e1f8b2b15fc0b7fc2cd3873a53b0a22>>
* @generated SignedSource<<d71fe8fc880922e5df9a2a0cbab38d57>>
*/

"use strict";
Expand Down Expand Up @@ -1204,38 +1204,35 @@ function diffProperties(updatePayload, prevProps, nextProps, validAttributes) {
)))));
return updatePayload;
}
function fastAddProperties(updatePayload, nextProps, validAttributes) {
function fastAddProperties(payload, props, validAttributes) {
var propKey;
for (propKey in nextProps) {
var nextProp = nextProps[propKey];
if (void 0 !== nextProp) {
for (propKey in props) {
var prop = props[propKey];
if (void 0 !== prop) {
var attributeConfig = validAttributes[propKey];
if (void 0 !== attributeConfig)
if (
("function" === typeof nextProp && (nextProp = !0),
"object" !== typeof attributeConfig)
)
updatePayload || (updatePayload = {}),
(updatePayload[propKey] = nextProp);
else if ("function" === typeof attributeConfig.process)
updatePayload || (updatePayload = {}),
(updatePayload[propKey] = attributeConfig.process(nextProp));
else if (isArrayImpl(nextProp))
for (var i = 0; i < nextProp.length; i++)
updatePayload = fastAddProperties(
updatePayload,
nextProp[i],
if (null != attributeConfig) {
var newValue = void 0;
"function" === typeof prop
? (newValue = !0)
: "object" !== typeof attributeConfig
? (newValue = prop)
: "function" === typeof attributeConfig.process
? (newValue = attributeConfig.process(prop))
: "function" === typeof attributeConfig.diff && (newValue = prop);
if (void 0 !== newValue)
payload || (payload = {}), (payload[propKey] = newValue);
else if (isArrayImpl(prop))
for (newValue = 0; newValue < prop.length; newValue++)
payload = fastAddProperties(
payload,
prop[newValue],
attributeConfig
);
else
updatePayload = fastAddProperties(
updatePayload,
nextProp,
attributeConfig
);
else payload = fastAddProperties(payload, prop, attributeConfig);
}
}
}
return updatePayload;
return payload;
}
function addProperties(updatePayload, props, validAttributes) {
return enableAddPropertiesFastPath
Expand Down Expand Up @@ -11297,7 +11294,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1204 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "19.0.0-beta-2b08380b",
version: "19.0.0-beta-13e56181",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
Expand Down Expand Up @@ -11353,7 +11350,7 @@ var roots = new Map(),
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-beta-2b08380b"
reconcilerVersion: "19.0.0-beta-13e56181"
});
exports.createPortal = function (children, containerTag) {
return createPortal$1(
Expand Down

0 comments on commit 34748be

Please sign in to comment.