Repository navigation
Commit 7612536
Fix Switch crash when onChange fires after view recycle (#59216)
Summary:
Fixes #59203.
`-[RCTSwitchComponentView onChange:]` dereferences `_eventEmitter` without checking it. `RCTViewComponentView -prepareForRecycle` resets `_eventEmitter`, and on iOS 26+ the redesigned `UISwitch` can deliver its `ValueChanged` action from a deferred `_UIAfterCACommitBlock` (e.g. after a drag/long-press). If the view gets recycled in between, `onChange:` runs on a recycled view and crashes with `EXC_BAD_ACCESS` inside `EventEmitter::dispatchEvent`.
This adds an early return when `_eventEmitter` is null, matching the existing guards in `RCTScrollViewComponentView`, `RCTImageComponentView`, `RCTModalHostViewComponentView` and `RCTVirtualViewComponentView`. Dropping the event is correct since the recycled view no longer represents that React node.
## Changelog:
[IOS] [FIXED] - Fix crash in `Switch` when `onChange` fires after the view has been recycled
Pull Request resolved: #59216
Test Plan:
- The crash is intermittent and timing-dependent (reported from production), so it is not reproducible on demand.
- The change is limited to an early-return null guard before the emitter dereference; normal toggling in RNTester's Switch examples is unaffected since `_eventEmitter` is set for mounted views.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Reviewed By: cipolleschi
Differential Revision: D126404965
Pulled By: javache
fbshipit-source-id: 5529c2f8d56cd9f9db5ea9f722e9e15794e2e8c11 parent 0bd3326 commit 7612536
1 file changed
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
113 | 117 | | |
114 | 118 | | |
115 | 119 | | |
| |||
0 commit comments