[iOS][Fabric] `RCTSwitchComponentView onChange:` dereferences `_eventEmitter` without a null check (EXC_BAD_ACCESS after view recycle)
Les mainteneurs répondent en général sous 2 jours
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 76/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- objective-c, react-native
- Domaine
- mobile
Piste de recherche
Lis React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm, en particulier onChange: et la gestion du recyclage à proximité mentionnée dans l’issue. Compare les gardes de l’event emitter dans les vues de composants voisines citées dans le rapport, puis vérifie les tests Switch pertinents ou ajoute une couverture pour une vue recyclée si les tests existants mettent ce cas en évidence. Le travail est terminé lorsque onChange: gère correctement un emitter effacé et que le comportement Switch existant reste couvert.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Environment
- react-native 0.88.0 (first seen on 0.86.0; the file is byte-identical in both), New Architecture
- iOS 26.5.2 device (production crash), same code path on iOS 27
- Expo SDK 58 (not involved)
Description
-[RCTSwitchComponentView onChange:] (React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm:105-114) ends with
static_cast<const SwitchEventEmitter &>(*_eventEmitter) // line 113
.onChange(SwitchEventEmitter::OnChange{.value = static_cast<bool>(sender.on)});
with no check that _eventEmitter is set. RCTViewComponentView -prepareForRecycle resets it (RCTViewComponentView.mm:779, _eventEmitter.reset();), while _props stays valid, so the earlier *_props dereference does not fail.
Production crash (0.86.0, line 114 of that version), iOS 26.5.2:
EXC_BAD_ACCESS (SIGSEGV) KERN_INVALID_ADDRESS at 0x0000000000000030
0 React std::weak_ptr<EventDispatcher const>::lock()
1 React EventEmitter::dispatchEvent(...)
4 React SwitchEventEmitter::onChange(...)
5 React -[RCTSwitchComponentView onChange:]
6 UIKitCore -[UIApplication sendAction:to:from:forEvent:]
9 UIKitCore -[UISwitchModernVisualElement sendStateChangeActions]
11 UIKitCore -[UISwitchModernVisualElement _handleLongPressWithGestureLocationInBounds:...]
12 UIKitCore -[_UIAfterCACommitBlock run]
0x30 is a null this plus the eventDispatcher_ offset in EventEmitter.
Reproduction
Intermittent, not reproduced on demand. Conditions: iOS 26+, where the redesigned UISwitch (UISwitchModernVisualElement) delivers the state-change action from a deferred _UIAfterCACommitBlock instead of synchronously on touch-up (seen when the switch is dragged or long-pressed rather than tapped). If React re-renders and recycles the Switch view between the gesture ending and that block running, prepareForRecycle has already cleared _eventEmitter and onChange: runs on the recycled view.
Root cause
Missing null guard. Sibling components in the same directory tree already have it: RCTScrollViewComponentView, RCTImageComponentView, RCTModalHostViewComponentView, RCTVirtualViewComponentView (if (!_eventEmitter) { return; }), and RCTTextInputComponentView tests _eventEmitter before use at several sites. Switch is the outlier.
Proposed fix
--- a/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm
+++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm
@@ -110,6 +110,9 @@ - (void)onChange:(UISwitch *)sender
return;
}
+ if (!_eventEmitter) {
+ return;
+ }
static_cast<const SwitchEventEmitter &>(*_eventEmitter)
.onChange(SwitchEventEmitter::OnChange{.value = static_cast<bool>(sender.on)});
}
We carry this as a local patch. Dropping the event is the right behaviour: the view has been recycled and no longer represents that React node.
Disclosure: drafted with AI assistance (Claude) from a patch we carry locally; code references were checked against the published package sources. Happy to clarify or open a PR.
- Langage dominant
- C++
- Étoiles
- 127k
- Forks
- 25.3k
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de react/react-native
-
Linking.getInitialURL() returns the task's first link after a link relaunches a reclaimed Android appPeut-être pris @YevheniiKotyrlo l’a pris il y a 7 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
react/react-native#59006 · 2 commentaires ·
Les mainteneurs répondent en général sous 2 jours
-
Fabric TextInput: prepareForRecycle leaves stale inputAccessoryViewButtonLabel (empty Done bar)Peut-être pris @jkasprzyk17 l’a pris il y a 6 jours. OuverteNeeds: Author Feedback Needs: Repro
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
react/react-native#58952 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
-
[iOS][Fabric] TextInput drops a keystroke right after the first character typed into an empty field (_textOf:equals: compares attributes of a focused field)Peut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. OuverteNeeds: Attention Needs: Repro
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
react/react-native#58904 · 3 commentaires ·
Les mainteneurs répondent en général sous 2 jours
-
Needs: Author Feedback Needs: Repro
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
react/react-native#58659 · 2 commentaires ·
Les mainteneurs répondent en général sous 2 jours
-
Needs: Author Feedback Needs: Repro
Difficulté 1/5 Moins d'une heure Accessibilité débutants 92/100
react/react-native#58621 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
Toutes les issues de react/react-native
Issues similaires
-
[WinReg] update to v12.0.0Ouvertecategory:port-update
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 2 jours
-
(S1 - Need confirmation)
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
CleverRaven/Cataclysm-DDA#89194 ·
Les mainteneurs répondent en général sous 1 jour
-
reproduced
Difficulté 1/5 Moins d'une heure Accessibilité débutants 67/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
Reusing a stream after a mid-speech stop: the next session opens with a phantom line ("you")Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
moonshine-ai/moonshine#231 ·