Commit 0e87de0
fix(iOS): reuse prefetched images (#57971)
Summary:
Fixes #28557.
iOS image prefetch stores decoded images using their original-size cache key. Later image requests often include concrete dimensions, producing a different cache key and causing the prefetched image to be downloaded again.
This change falls back to the original-size cache entry for sized requests and reports prefetched decoded images as available in memory through `Image.queryCache()`.
## Changelog:
[IOS] [FIXED] - Reuse prefetched images for subsequent sized image requests
Pull Request resolved: #57971
Test Plan:
- `git diff --check` — passed.
- Tested with RNTester on an iPhone simulator running iOS 26.5.
- Opened **Image → Image Loading Events**.
- Verified `Image.prefetch()` completed successfully.
- Verified `Image.queryCache()` returned `disk/memory`.
- Verified the prefetched image loaded and rendered at the requested dimensions without unexpected stretching, cropping, or distortion.
Screenshot:
<img width="318" height="604" alt="Screenshot 2026-08-16 at 12 09 30 PM" src="https://github.com/user-attachments/assets/c6db4ce4-d130-47d3-ae64-0a62f5e5385e" />
Reviewed By: cipolleschi
Differential Revision: D118334375
Pulled By: javache
fbshipit-source-id: 3ed64fdde88beb3476056fb0f4ac5acc294ce4ae1 parent 665beff commit 0e87de0
2 files changed
Lines changed: 142 additions & 20 deletions
File tree
- packages
- react-native/Libraries/Image
- rn-tester/RNTesterUnitTests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
189 | | - | |
190 | | - | |
191 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
192 | 197 | | |
193 | | - | |
194 | 198 | | |
195 | 199 | | |
196 | 200 | | |
197 | 201 | | |
198 | | - | |
199 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
200 | 207 | | |
201 | | - | |
202 | 208 | | |
203 | 209 | | |
204 | 210 | | |
| |||
311 | 317 | | |
312 | 318 | | |
313 | 319 | | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
314 | 342 | | |
315 | 343 | | |
316 | 344 | | |
| |||
492 | 520 | | |
493 | 521 | | |
494 | 522 | | |
| 523 | + | |
495 | 524 | | |
496 | 525 | | |
497 | 526 | | |
| |||
542 | 571 | | |
543 | 572 | | |
544 | 573 | | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
| 574 | + | |
| 575 | + | |
549 | 576 | | |
550 | 577 | | |
551 | 578 | | |
| |||
662 | 689 | | |
663 | 690 | | |
664 | 691 | | |
665 | | - | |
666 | | - | |
667 | | - | |
668 | | - | |
| 692 | + | |
| 693 | + | |
669 | 694 | | |
670 | 695 | | |
671 | 696 | | |
| |||
889 | 914 | | |
890 | 915 | | |
891 | 916 | | |
| 917 | + | |
892 | 918 | | |
893 | 919 | | |
894 | 920 | | |
| |||
1107 | 1133 | | |
1108 | 1134 | | |
1109 | 1135 | | |
| 1136 | + | |
1110 | 1137 | | |
1111 | 1138 | | |
1112 | 1139 | | |
| |||
1121 | 1148 | | |
1122 | 1149 | | |
1123 | 1150 | | |
1124 | | - | |
| 1151 | + | |
| 1152 | + | |
1125 | 1153 | | |
1126 | 1154 | | |
1127 | 1155 | | |
1128 | | - | |
| 1156 | + | |
1129 | 1157 | | |
1130 | 1158 | | |
1131 | 1159 | | |
1132 | | - | |
| 1160 | + | |
1133 | 1161 | | |
1134 | | - | |
| 1162 | + | |
1135 | 1163 | | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
1136 | 1167 | | |
1137 | 1168 | | |
1138 | 1169 | | |
| |||
Lines changed: 92 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
23 | 114 | | |
24 | 115 | | |
25 | 116 | | |
| |||
0 commit comments