Skip to content

Commit 43aae66

Browse files
Send same-URI Image source changes in Props 2.0 payloads
ImageProps::getDiffProps now compares every serialized field of each source instead of ImageSource::operator==, which stays the type-and-URI identity used for image requests. A same-URI change to the headers, cache policy, size or scale now sends the source and its headers.
1 parent 7ca06b9 commit 43aae66

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

  • packages/react-native/ReactCommon/react/renderer/components/image

‎packages/react-native/ReactCommon/react/renderer/components/image/ImageProps.cpp‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include <react/renderer/debug/debugStringConvertibleUtils.h>
1313
#include <react/renderer/graphics/Color.h>
1414

15+
#include <algorithm>
16+
#include <tuple>
17+
1518
namespace facebook::react {
1619

1720
ImageProps::ImageProps(
@@ -145,6 +148,30 @@ static folly::dynamic convertEdgeInsets(const EdgeInsets& edgeInsets) {
145148
return edgeInsetsResult;
146149
}
147150

151+
// ImageSource::operator== compares only the request identity: type and URI.
152+
static bool hasSamePayload(const ImageSource& lhs, const ImageSource& rhs) {
153+
return std::tie(
154+
lhs.type,
155+
lhs.uri,
156+
lhs.bundle,
157+
lhs.scale,
158+
lhs.size,
159+
lhs.body,
160+
lhs.method,
161+
lhs.cache,
162+
lhs.headers) ==
163+
std::tie(
164+
rhs.type,
165+
rhs.uri,
166+
rhs.bundle,
167+
rhs.scale,
168+
rhs.size,
169+
rhs.body,
170+
rhs.method,
171+
rhs.cache,
172+
rhs.headers);
173+
}
174+
148175
ComponentName ImageProps::getDiffPropsImplementationTarget() const {
149176
return "Image";
150177
}
@@ -158,7 +185,7 @@ folly::dynamic ImageProps::getDiffProps(const Props* prevProps) const {
158185

159186
folly::dynamic result = ViewProps::getDiffProps(oldProps);
160187

161-
if (sources != oldProps->sources) {
188+
if (!std::ranges::equal(sources, oldProps->sources, hasSamePayload)) {
162189
auto sourcesArray = folly::dynamic::array();
163190
for (const auto& source : sources) {
164191
sourcesArray.push_back(toDynamic(source));

0 commit comments

Comments
 (0)