Skip to content

Commit 7ca06b9

Browse files
[repro] Image Props 2.0 payload: same-URI source changes are not sent
ImageProps::getDiffProps compares sources with ImageSource::operator==, which compares only type and URI. A source that keeps its URI but changes its headers, cache policy, size or scale is therefore not sent, and neither are the derived headers: ReactImageView keeps the old cache control and multi-source sizes, and ReactImageManager keeps the old request headers. The test fails on main.
1 parent 6a45453 commit 7ca06b9

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ TEST(ImagePropsDiffTest, removingTintColorEmitsNull) {
6666
});
6767
}
6868

69+
// ReactImageView reads the cache policy and the sizes of each source, and
70+
// ReactImageManager the headers; a source with the same URI can change them.
71+
TEST(ImagePropsDiffTest, emitsASameUriSourceWhenItsOtherFieldsChange) {
72+
dynamic headers = dynamic::object("Authorization", "old");
73+
dynamic source = dynamic::object("uri", "https://a")("width", 10)(
74+
"height", 20)("scale", 1)("cache", "default")("headers", headers);
75+
std::vector<PropsCommit> commits{
76+
{dynamic::object("source", dynamic::array(source))("headers", headers)}};
77+
dynamic changes = dynamic::object("cache", "reload")("width", 30)("scale", 2);
78+
for (const auto& [field, value] : changes.items()) {
79+
source[field] = value;
80+
// Props 2.0 sends the first source's headers whenever the sources change.
81+
commits.push_back(
82+
{dynamic::object("source", dynamic::array(source)),
83+
dynamic::object("headers", headers)});
84+
}
85+
source["headers"] = dynamic::object("Authorization", "new");
86+
commits.push_back({dynamic::object("source", dynamic::array(source))(
87+
"headers", source["headers"])});
88+
expectPayloads(commits);
89+
}
90+
6991
} // namespace facebook::react
7092

7193
#endif

0 commit comments

Comments
 (0)