Skip to content

Commit

Permalink
Add tests for ReactNativeAttributePayloadFabric.js (#29608)
Browse files Browse the repository at this point in the history
## Summary

This PR add tests for `ReactNativeAttributePayloadFabric.js`.

It introduces `ReactNativeAttributePayloadFabric-test.internal.js`,
which is a copy-paste of `ReactNativeAttributePayload-test.internal.js`.

On top of that, there is a bunch of new test cases for the
`ReactNativeAttributePayloadFabric.create` function.

## How did you test this change?

```
yarn test packages/react-native-renderer
```

DiffTrain build for commit 51dd096.
  • Loading branch information
dmytrorykun committed May 30, 2024
1 parent 3546ca6 commit b0cfb9c
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
38e3b23483bf7a612391cd617a8926aa1f3cf52e
51dd09631ac0c7824fec55f38462846b6fe41d06
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<715c7ff1aa207b21918f50cdc5380bf6>>
* @generated SignedSource<<ab8d28628a6daaeaf3d5ca2abe1262e5>>
*/

'use strict';
Expand Down Expand Up @@ -2364,17 +2364,23 @@ function diffProperties(updatePayload, prevProps, nextProps, validAttributes) {
}

function fastAddProperties(payload, props, validAttributes) {
var attributeConfig;
var prop;
// Flatten nested style props.
if (isArray(props)) {
for (var i = 0; i < props.length; i++) {
payload = fastAddProperties(payload, props[i], validAttributes);
}

return payload;
}

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

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

attributeConfig = validAttributes[propKey];
var attributeConfig = validAttributes[propKey];

if (attributeConfig == null) {
continue;
Expand All @@ -2392,7 +2398,7 @@ function fastAddProperties(payload, props, validAttributes) {
// 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.
// An atomic prop with custom diffing. We don't need to do diffing when adding props.
newValue = prop;
}

Expand All @@ -2403,18 +2409,7 @@ function fastAddProperties(payload, props, validAttributes) {

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(prop)) {
for (var i = 0; i < prop.length; i++) {
payload = fastAddProperties(payload, prop[i], attributeConfig);
}

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

}

payload = fastAddProperties(payload, prop, attributeConfig);
}
Expand All @@ -2427,11 +2422,7 @@ function fastAddProperties(payload, props, validAttributes) {


function addProperties(updatePayload, props, validAttributes) {
if (enableAddPropertiesFastPath) {
return fastAddProperties(updatePayload, props, validAttributes);
} else {
return diffProperties(updatePayload, emptyObject$1, props, validAttributes);
}
return diffProperties(updatePayload, emptyObject$1, props, validAttributes);
}
/**
* clearProperties clears all the previous props by adding a null sentinel
Expand All @@ -2445,8 +2436,11 @@ function clearProperties(updatePayload, prevProps, validAttributes) {
}

function create(props, validAttributes) {
return addProperties(null, // updatePayload
props, validAttributes);
if (enableAddPropertiesFastPath) {
return fastAddProperties(null, props, validAttributes);
} else {
return addProperties(null, props, validAttributes);
}
}
function diff(prevProps, nextProps, validAttributes) {
return diffProperties(null, // updatePayload
Expand Down Expand Up @@ -26212,7 +26206,7 @@ identifierPrefix, onUncaughtError, onCaughtError, onRecoverableError, transition
return root;
}

var ReactVersion = '19.0.0-rc-6b65a277';
var ReactVersion = '19.0.0-rc-eb8ea74f';

/*
* 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<<e220fc857a21f1b640cba2d994902482>>
* @generated SignedSource<<6a822844da38fad5149fb7f36a73eb44>>
*/

"use strict";
Expand Down Expand Up @@ -1085,7 +1085,12 @@ function diffNestedProperty(
function addNestedProperty(updatePayload, nextProp, validAttributes) {
if (!nextProp) return updatePayload;
if (!isArrayImpl(nextProp))
return addProperties(updatePayload, nextProp, validAttributes);
return diffProperties(
updatePayload,
emptyObject$1,
nextProp,
validAttributes
);
for (var i = 0; i < nextProp.length; i++)
updatePayload = addNestedProperty(
updatePayload,
Expand Down Expand Up @@ -1196,11 +1201,15 @@ function diffProperties(updatePayload, prevProps, nextProps, validAttributes) {
return updatePayload;
}
function fastAddProperties(payload, props, validAttributes) {
var propKey;
for (propKey in props) {
var prop = props[propKey];
if (isArrayImpl(props)) {
for (var i = 0; i < props.length; i++)
payload = fastAddProperties(payload, props[i], validAttributes);
return payload;
}
for (i in props) {
var prop = props[i];
if (void 0 !== prop) {
var attributeConfig = validAttributes[propKey];
var attributeConfig = validAttributes[i];
if (null != attributeConfig) {
var newValue = void 0;
"function" === typeof prop
Expand All @@ -1210,25 +1219,18 @@ function fastAddProperties(payload, props, validAttributes) {
: "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 payload = fastAddProperties(payload, prop, attributeConfig);
void 0 !== newValue
? (payload || (payload = {}), (payload[i] = newValue))
: (payload = fastAddProperties(payload, prop, attributeConfig));
}
}
}
return payload;
}
function addProperties(updatePayload, props, validAttributes) {
function create(props, validAttributes) {
return enableAddPropertiesFastPath
? fastAddProperties(updatePayload, props, validAttributes)
: diffProperties(updatePayload, emptyObject$1, props, validAttributes);
? fastAddProperties(null, props, validAttributes)
: diffProperties(null, emptyObject$1, props, validAttributes);
}
function batchedUpdatesImpl(fn, bookkeeping) {
return fn(bookkeeping);
Expand Down Expand Up @@ -1629,14 +1631,13 @@ function resolveUpdatePriority() {
var scheduleTimeout = setTimeout,
cancelTimeout = clearTimeout;
function cloneHiddenInstance(instance) {
var node = instance.node;
var JSCompiler_inline_result = addProperties(
null,
{ style: { display: "none" } },
instance.canonical.viewConfig.validAttributes
);
var node = instance.node,
updatePayload = create(
{ style: { display: "none" } },
instance.canonical.viewConfig.validAttributes
);
return {
node: cloneNodeWithNewProps(node, JSCompiler_inline_result),
node: cloneNodeWithNewProps(node, updatePayload),
canonical: instance.canonical
};
}
Expand Down Expand Up @@ -7321,11 +7322,7 @@ function completeWork(current, workInProgress, renderLanes) {
current = nextReactTag;
nextReactTag += 2;
renderLanes = getViewConfigForType(renderLanes);
newChildSet = addProperties(
null,
newProps,
renderLanes.validAttributes
);
newChildSet = create(newProps, renderLanes.validAttributes);
oldProps = createNode(
current,
renderLanes.uiViewClassName,
Expand Down Expand Up @@ -10554,7 +10551,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1124 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "19.0.0-rc-a1153661",
version: "19.0.0-rc-d92431d2",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
Expand All @@ -10570,7 +10567,7 @@ var roots = new Map(),
}.bind(null, findNodeHandle)
}
};
var internals$jscomp$inline_1354 = {
var internals$jscomp$inline_1350 = {
bundleType: devToolsConfig$jscomp$inline_1124.bundleType,
version: devToolsConfig$jscomp$inline_1124.version,
rendererPackageName: devToolsConfig$jscomp$inline_1124.rendererPackageName,
Expand All @@ -10597,19 +10594,19 @@ var internals$jscomp$inline_1354 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-rc-a1153661"
reconcilerVersion: "19.0.0-rc-d92431d2"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1355 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
var hook$jscomp$inline_1351 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
if (
!hook$jscomp$inline_1355.isDisabled &&
hook$jscomp$inline_1355.supportsFiber
!hook$jscomp$inline_1351.isDisabled &&
hook$jscomp$inline_1351.supportsFiber
)
try {
(rendererID = hook$jscomp$inline_1355.inject(
internals$jscomp$inline_1354
(rendererID = hook$jscomp$inline_1351.inject(
internals$jscomp$inline_1350
)),
(injectedHook = hook$jscomp$inline_1355);
(injectedHook = hook$jscomp$inline_1351);
} catch (err) {}
}
exports.createPortal = function (children, containerTag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<2e682bd27fce85dbf44c7d76dad0d567>>
* @generated SignedSource<<dc3b2aaa3c81338654d45795eca7bd82>>
*/

"use strict";
Expand Down Expand Up @@ -1089,7 +1089,12 @@ function diffNestedProperty(
function addNestedProperty(updatePayload, nextProp, validAttributes) {
if (!nextProp) return updatePayload;
if (!isArrayImpl(nextProp))
return addProperties(updatePayload, nextProp, validAttributes);
return diffProperties(
updatePayload,
emptyObject$1,
nextProp,
validAttributes
);
for (var i = 0; i < nextProp.length; i++)
updatePayload = addNestedProperty(
updatePayload,
Expand Down Expand Up @@ -1200,11 +1205,15 @@ function diffProperties(updatePayload, prevProps, nextProps, validAttributes) {
return updatePayload;
}
function fastAddProperties(payload, props, validAttributes) {
var propKey;
for (propKey in props) {
var prop = props[propKey];
if (isArrayImpl(props)) {
for (var i = 0; i < props.length; i++)
payload = fastAddProperties(payload, props[i], validAttributes);
return payload;
}
for (i in props) {
var prop = props[i];
if (void 0 !== prop) {
var attributeConfig = validAttributes[propKey];
var attributeConfig = validAttributes[i];
if (null != attributeConfig) {
var newValue = void 0;
"function" === typeof prop
Expand All @@ -1214,25 +1223,18 @@ function fastAddProperties(payload, props, validAttributes) {
: "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 payload = fastAddProperties(payload, prop, attributeConfig);
void 0 !== newValue
? (payload || (payload = {}), (payload[i] = newValue))
: (payload = fastAddProperties(payload, prop, attributeConfig));
}
}
}
return payload;
}
function addProperties(updatePayload, props, validAttributes) {
function create(props, validAttributes) {
return enableAddPropertiesFastPath
? fastAddProperties(updatePayload, props, validAttributes)
: diffProperties(updatePayload, emptyObject$1, props, validAttributes);
? fastAddProperties(null, props, validAttributes)
: diffProperties(null, emptyObject$1, props, validAttributes);
}
function batchedUpdatesImpl(fn, bookkeeping) {
return fn(bookkeeping);
Expand Down Expand Up @@ -1751,14 +1753,13 @@ function resolveUpdatePriority() {
var scheduleTimeout = setTimeout,
cancelTimeout = clearTimeout;
function cloneHiddenInstance(instance) {
var node = instance.node;
var JSCompiler_inline_result = addProperties(
null,
{ style: { display: "none" } },
instance.canonical.viewConfig.validAttributes
);
var node = instance.node,
updatePayload = create(
{ style: { display: "none" } },
instance.canonical.viewConfig.validAttributes
);
return {
node: cloneNodeWithNewProps(node, JSCompiler_inline_result),
node: cloneNodeWithNewProps(node, updatePayload),
canonical: instance.canonical
};
}
Expand Down Expand Up @@ -7587,11 +7588,7 @@ function completeWork(current, workInProgress, renderLanes) {
current = nextReactTag;
nextReactTag += 2;
renderLanes = getViewConfigForType(renderLanes);
newChildSet = addProperties(
null,
newProps,
renderLanes.validAttributes
);
newChildSet = create(newProps, renderLanes.validAttributes);
oldProps = createNode(
current,
renderLanes.uiViewClassName,
Expand Down Expand Up @@ -11260,7 +11257,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1205 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "19.0.0-rc-cefeada5",
version: "19.0.0-rc-ae69ed52",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
Expand Down Expand Up @@ -11316,7 +11313,7 @@ var roots = new Map(),
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-rc-cefeada5"
reconcilerVersion: "19.0.0-rc-ae69ed52"
});
exports.createPortal = function (children, containerTag) {
return createPortal$1(
Expand Down

0 comments on commit b0cfb9c

Please sign in to comment.