Skip to content

Commit 34748be

Browse files
committed
Clean up fastAddProperties and make it more correct (#29015)
## 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.
1 parent acdffc0 commit 34748be

4 files changed

Lines changed: 88 additions & 88 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
703983426243422d9726ca3a0c7eef54e173a6bb
1+
b37e4b4e616d6d66c1cde9c0a4c2cbd866b0b582

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<854ee92767fe1d880e62f5cc7c83d537>>
10+
* @generated SignedSource<<577c7636235832d840ad016860b50817>>
1111
*/
1212

1313
'use strict';
@@ -2350,57 +2350,63 @@ function diffProperties(updatePayload, prevProps, nextProps, validAttributes) {
23502350
return updatePayload;
23512351
}
23522352

2353-
function fastAddProperties(updatePayload, nextProps, validAttributes) {
2353+
function fastAddProperties(payload, props, validAttributes) {
23542354
var attributeConfig;
2355-
var nextProp;
2355+
var prop;
23562356

2357-
for (var propKey in nextProps) {
2358-
nextProp = nextProps[propKey];
2357+
for (var propKey in props) {
2358+
prop = props[propKey];
23592359

2360-
if (nextProp === undefined) {
2360+
if (prop === undefined) {
23612361
continue;
23622362
}
23632363

23642364
attributeConfig = validAttributes[propKey];
23652365

2366-
if (attributeConfig === undefined) {
2366+
if (attributeConfig == null) {
23672367
continue;
23682368
}
23692369

2370-
if (typeof nextProp === 'function') {
2371-
nextProp = true;
2372-
}
2373-
2374-
if (typeof attributeConfig !== 'object') {
2375-
if (!updatePayload) {
2376-
updatePayload = {};
2377-
}
2370+
var newValue = void 0;
23782371

2379-
updatePayload[propKey] = nextProp;
2380-
continue;
2372+
if (typeof prop === 'function') {
2373+
// A function prop. It represents an event handler. Pass it to native as 'true'.
2374+
newValue = true;
2375+
} else if (typeof attributeConfig !== 'object') {
2376+
// An atomic prop. Doesn't need to be flattened.
2377+
newValue = prop;
2378+
} else if (typeof attributeConfig.process === 'function') {
2379+
// An atomic prop with custom processing.
2380+
newValue = attributeConfig.process(prop);
2381+
} else if (typeof attributeConfig.diff === 'function') {
2382+
// An atomic prop with custom diffing. We don't do diffing here.
2383+
newValue = prop;
23812384
}
23822385

2383-
if (typeof attributeConfig.process === 'function') {
2384-
if (!updatePayload) {
2385-
updatePayload = {};
2386+
if (newValue !== undefined) {
2387+
if (!payload) {
2388+
payload = {};
23862389
}
23872390

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

2392-
if (isArray(nextProp)) {
2393-
for (var i = 0; i < nextProp.length; i++) {
2394-
updatePayload = fastAddProperties(updatePayload, nextProp[i], attributeConfig);
2397+
if (isArray(prop)) {
2398+
for (var i = 0; i < prop.length; i++) {
2399+
payload = fastAddProperties(payload, prop[i], attributeConfig);
23952400
}
23962401

23972402
continue;
2398-
}
2403+
} // Or it can be an object.
2404+
23992405

2400-
updatePayload = fastAddProperties(updatePayload, nextProp, attributeConfig);
2406+
payload = fastAddProperties(payload, prop, attributeConfig);
24012407
}
24022408

2403-
return updatePayload;
2409+
return payload;
24042410
}
24052411
/**
24062412
* addProperties adds all the valid props to the payload after being processed.
@@ -26089,7 +26095,7 @@ identifierPrefix, onUncaughtError, onCaughtError, onRecoverableError, transition
2608926095
return root;
2609026096
}
2609126097

26092-
var ReactVersion = '19.0.0-beta-bf4ea329';
26098+
var ReactVersion = '19.0.0-beta-83bc2843';
2609326099

2609426100
/*
2609526101
* The `'' + value` pattern (used in perf-sensitive code) throws for Symbol

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<4d85e00114107b7747eb3de320972dc1>>
10+
* @generated SignedSource<<844a7fde793a6bcbd87492fec25685e4>>
1111
*/
1212

1313
"use strict";
@@ -1200,38 +1200,35 @@ function diffProperties(updatePayload, prevProps, nextProps, validAttributes) {
12001200
)))));
12011201
return updatePayload;
12021202
}
1203-
function fastAddProperties(updatePayload, nextProps, validAttributes) {
1203+
function fastAddProperties(payload, props, validAttributes) {
12041204
var propKey;
1205-
for (propKey in nextProps) {
1206-
var nextProp = nextProps[propKey];
1207-
if (void 0 !== nextProp) {
1205+
for (propKey in props) {
1206+
var prop = props[propKey];
1207+
if (void 0 !== prop) {
12081208
var attributeConfig = validAttributes[propKey];
1209-
if (void 0 !== attributeConfig)
1210-
if (
1211-
("function" === typeof nextProp && (nextProp = !0),
1212-
"object" !== typeof attributeConfig)
1213-
)
1214-
updatePayload || (updatePayload = {}),
1215-
(updatePayload[propKey] = nextProp);
1216-
else if ("function" === typeof attributeConfig.process)
1217-
updatePayload || (updatePayload = {}),
1218-
(updatePayload[propKey] = attributeConfig.process(nextProp));
1219-
else if (isArrayImpl(nextProp))
1220-
for (var i = 0; i < nextProp.length; i++)
1221-
updatePayload = fastAddProperties(
1222-
updatePayload,
1223-
nextProp[i],
1209+
if (null != attributeConfig) {
1210+
var newValue = void 0;
1211+
"function" === typeof prop
1212+
? (newValue = !0)
1213+
: "object" !== typeof attributeConfig
1214+
? (newValue = prop)
1215+
: "function" === typeof attributeConfig.process
1216+
? (newValue = attributeConfig.process(prop))
1217+
: "function" === typeof attributeConfig.diff && (newValue = prop);
1218+
if (void 0 !== newValue)
1219+
payload || (payload = {}), (payload[propKey] = newValue);
1220+
else if (isArrayImpl(prop))
1221+
for (newValue = 0; newValue < prop.length; newValue++)
1222+
payload = fastAddProperties(
1223+
payload,
1224+
prop[newValue],
12241225
attributeConfig
12251226
);
1226-
else
1227-
updatePayload = fastAddProperties(
1228-
updatePayload,
1229-
nextProp,
1230-
attributeConfig
1231-
);
1227+
else payload = fastAddProperties(payload, prop, attributeConfig);
1228+
}
12321229
}
12331230
}
1234-
return updatePayload;
1231+
return payload;
12351232
}
12361233
function addProperties(updatePayload, props, validAttributes) {
12371234
return enableAddPropertiesFastPath
@@ -10592,7 +10589,7 @@ var roots = new Map(),
1059210589
devToolsConfig$jscomp$inline_1124 = {
1059310590
findFiberByHostInstance: getInstanceFromNode,
1059410591
bundleType: 0,
10595-
version: "19.0.0-beta-8abbffa0",
10592+
version: "19.0.0-beta-bdce1f91",
1059610593
rendererPackageName: "react-native-renderer",
1059710594
rendererConfig: {
1059810595
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -10635,7 +10632,7 @@ var internals$jscomp$inline_1356 = {
1063510632
scheduleRoot: null,
1063610633
setRefreshHandler: null,
1063710634
getCurrentFiber: null,
10638-
reconcilerVersion: "19.0.0-beta-8abbffa0"
10635+
reconcilerVersion: "19.0.0-beta-bdce1f91"
1063910636
};
1064010637
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1064110638
var hook$jscomp$inline_1357 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<3e1f8b2b15fc0b7fc2cd3873a53b0a22>>
10+
* @generated SignedSource<<d71fe8fc880922e5df9a2a0cbab38d57>>
1111
*/
1212

1313
"use strict";
@@ -1204,38 +1204,35 @@ function diffProperties(updatePayload, prevProps, nextProps, validAttributes) {
12041204
)))));
12051205
return updatePayload;
12061206
}
1207-
function fastAddProperties(updatePayload, nextProps, validAttributes) {
1207+
function fastAddProperties(payload, props, validAttributes) {
12081208
var propKey;
1209-
for (propKey in nextProps) {
1210-
var nextProp = nextProps[propKey];
1211-
if (void 0 !== nextProp) {
1209+
for (propKey in props) {
1210+
var prop = props[propKey];
1211+
if (void 0 !== prop) {
12121212
var attributeConfig = validAttributes[propKey];
1213-
if (void 0 !== attributeConfig)
1214-
if (
1215-
("function" === typeof nextProp && (nextProp = !0),
1216-
"object" !== typeof attributeConfig)
1217-
)
1218-
updatePayload || (updatePayload = {}),
1219-
(updatePayload[propKey] = nextProp);
1220-
else if ("function" === typeof attributeConfig.process)
1221-
updatePayload || (updatePayload = {}),
1222-
(updatePayload[propKey] = attributeConfig.process(nextProp));
1223-
else if (isArrayImpl(nextProp))
1224-
for (var i = 0; i < nextProp.length; i++)
1225-
updatePayload = fastAddProperties(
1226-
updatePayload,
1227-
nextProp[i],
1213+
if (null != attributeConfig) {
1214+
var newValue = void 0;
1215+
"function" === typeof prop
1216+
? (newValue = !0)
1217+
: "object" !== typeof attributeConfig
1218+
? (newValue = prop)
1219+
: "function" === typeof attributeConfig.process
1220+
? (newValue = attributeConfig.process(prop))
1221+
: "function" === typeof attributeConfig.diff && (newValue = prop);
1222+
if (void 0 !== newValue)
1223+
payload || (payload = {}), (payload[propKey] = newValue);
1224+
else if (isArrayImpl(prop))
1225+
for (newValue = 0; newValue < prop.length; newValue++)
1226+
payload = fastAddProperties(
1227+
payload,
1228+
prop[newValue],
12281229
attributeConfig
12291230
);
1230-
else
1231-
updatePayload = fastAddProperties(
1232-
updatePayload,
1233-
nextProp,
1234-
attributeConfig
1235-
);
1231+
else payload = fastAddProperties(payload, prop, attributeConfig);
1232+
}
12361233
}
12371234
}
1238-
return updatePayload;
1235+
return payload;
12391236
}
12401237
function addProperties(updatePayload, props, validAttributes) {
12411238
return enableAddPropertiesFastPath
@@ -11297,7 +11294,7 @@ var roots = new Map(),
1129711294
devToolsConfig$jscomp$inline_1204 = {
1129811295
findFiberByHostInstance: getInstanceFromNode,
1129911296
bundleType: 0,
11300-
version: "19.0.0-beta-2b08380b",
11297+
version: "19.0.0-beta-13e56181",
1130111298
rendererPackageName: "react-native-renderer",
1130211299
rendererConfig: {
1130311300
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -11353,7 +11350,7 @@ var roots = new Map(),
1135311350
scheduleRoot: null,
1135411351
setRefreshHandler: null,
1135511352
getCurrentFiber: null,
11356-
reconcilerVersion: "19.0.0-beta-2b08380b"
11353+
reconcilerVersion: "19.0.0-beta-13e56181"
1135711354
});
1135811355
exports.createPortal = function (children, containerTag) {
1135911356
return createPortal$1(

0 commit comments

Comments
 (0)