Commit fc3443f
Fix VoiceOver infinite recursion crash when delegate set to collectionView (Issue 1658)
Summary:
#1658
This fix addresses a crash that occurs when VoiceOver is enabled and `scrollViewDelegate` or `collectionViewDelegate` is set to the adapter's own `UICollectionView`.
## The Problem
When VoiceOver is enabled, accessibility queries trigger delegate method calls on the collection view. If the collection view is also set as its own scroll view delegate (via `IGListAdapter`'s proxy), these delegate calls get forwarded back to the collection view, creating infinite recursion:
1. VoiceOver queries accessibility on collectionView
2. `collectionView.delegate` (the proxy) forwards to `scrollViewTarget`
3. `scrollViewTarget` IS the collectionView → back to step 1
4. Stack overflow crash
Example crash-triggering code:
```
adapter.collectionView = collectionView
adapter.scrollViewDelegate = collectionView // Crash with VoiceOver!
```
## The Fix
Here I've added validation in three places to prevent this configuration:
1. `setScrollViewDelegate:` - Rejects if `delegate == collectionView`
2. `setCollectionViewDelegate:` - Rejects if `delegate == collectionView`
3. `setCollectionView:` - Clears delegates if they equal the new collectionView
## Why This Is Safe (No Negative Side Effects)
**Setting UICollectionView as its own delegate provides no useful functionality:**
- `UICollectionView` already handles scroll events internally (it's a `UIScrollView` subclass)
- The `collectionView` doesn't implement custom `UIScrollViewDelegate` methods
- This configuration ONLY results in crashes when VoiceOver is enabled
**Behavior change is strictly beneficial:**
- Before: Works without VoiceOver, crashes WITH VoiceOver
- After: Silently rejects invalid config, works with VoiceOver
**Developer feedback is preserved:**
- `IGFailAssert` fires in `DEBUG` builds to alert developers to fix their code
- Production gracefully handles the situation instead of crashing
**No breaking changes for valid usage:**
- Normal delegate patterns (separate delegate objects) are unaffected
- Only the invalid self-referential pattern is blocked
See: #1658
Reviewed By: dinhvh
Differential Revision: D100641752
fbshipit-source-id: a1885c4ede6ca0555f3f94dd0c72b328a5af62bc1 parent 01887c6 commit fc3443f
3 files changed
Lines changed: 88 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
8 | 12 | | |
9 | 13 | | |
10 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
115 | 129 | | |
116 | 130 | | |
117 | 131 | | |
| |||
169 | 183 | | |
170 | 184 | | |
171 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
172 | 194 | | |
173 | 195 | | |
174 | 196 | | |
| |||
178 | 200 | | |
179 | 201 | | |
180 | 202 | | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
181 | 211 | | |
182 | 212 | | |
183 | 213 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2382 | 2382 | | |
2383 | 2383 | | |
2384 | 2384 | | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
| 2419 | + | |
| 2420 | + | |
| 2421 | + | |
| 2422 | + | |
| 2423 | + | |
| 2424 | + | |
| 2425 | + | |
| 2426 | + | |
| 2427 | + | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
2385 | 2439 | | |
0 commit comments