Opt-out of React Native Fabric view recycling for ExpoFabricViewObjC
Kureev
On iOS, Fabric aggressively recycles component views for performance. The ExpoFabricViewObjC wrapper currently doesn’t override shouldBeRecycled, which means it may be reused by Fabric even though the inner Expo view may not be recycle-safe. This can lead to state leakage, stale UI, or crashes when views with native resources (images, GL surfaces, video, camera, etc.) are mounted/unmounted in quick succession.
Proposed change
Add:
(BOOL)shouldBeRecycled
{
return NO;
}
to ExpoFabricViewObjC.mm. This disables view pooling for this wrapper, ensuring each instance is freshly created.
Rationale
- Many Expo views hold native resources that don’t reset cleanly on recycle.
- Without this safeguard, recycled views can render wrong content, keep dangling observers, or crash.
- Opting out of recycling prioritizes correctness/stability over marginal perf gains until a safe recycling path exists.
Potential downside
- Higher allocation rate and memory pressure in large lists.
- Minor perf regressions compared to view pooling.