Add codegen for MixedType diffing (#52266)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/52266

Native components may use `MixedType` properties in rare cases to hold untyped data. This diff adds support for serializing and prop diffing these types of props so that all of the props and object fields would be included in prop diffing results.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D77307169

fbshipit-source-id: ae6b00207ef857c9cfa4bdf9c235972915410a29
This commit is contained in:
Nick Lefever
2025-06-25 18:28:22 -07:00
committed by Facebook GitHub Bot
parent e441954c82
commit 53ce247dbd
5 changed files with 14 additions and 3 deletions
@@ -737,6 +737,9 @@ folly::dynamic MixedPropNativeComponentViewProps::getDiffProps(
}
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
if (mixedProp != oldProps->mixedProp) {
result[\\"mixedProp\\"] = mixedProp;
}
return result;
}
#endif
@@ -737,6 +737,9 @@ folly::dynamic MixedPropNativeComponentViewProps::getDiffProps(
}
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
if (mixedProp != oldProps->mixedProp) {
result[\\"mixedProp\\"] = mixedProp;
}
return result;
}
#endif
@@ -152,6 +152,10 @@ function generatePropsDiffString(
result["${prop.name}"] = toDynamic(${prop.name});
}`;
case 'MixedTypeAnnotation':
return `
if (${prop.name} != oldProps->${prop.name}) {
result["${prop.name}"] = ${prop.name};
}`;
default:
// TODO: Implement diffProps for complex types
return '';
@@ -755,10 +755,8 @@ function generateStruct(
case 'Int32TypeAnnotation':
case 'DoubleTypeAnnotation':
case 'FloatTypeAnnotation':
return `result["${name}"] = ${name};`;
case 'MixedTypeAnnotation':
// MixedTypeAnnotation does not support prop diffing codegen
return '';
return `result["${name}"] = ${name};`;
default:
return `result["${name}"] = ::facebook::react::toDynamic(${name});`;
}
@@ -1152,6 +1152,9 @@ folly::dynamic MixedPropNativeComponentProps::getDiffProps(
}
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
if (mixedProp != oldProps->mixedProp) {
result[\\"mixedProp\\"] = mixedProp;
}
return result;
}
#endif