[iOS][Fabric] `RCTSwitchComponentView onChange:` dereferences `_eventEmitter` without a null check (EXC_BAD_ACCESS after view recycle)
Los mantenedores suelen responder en 2 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 76/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- objective-c, react-native
- Área
- mobile
Línea de trabajo
Lee React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm, especialmente onChange: y el manejo cercano del reciclaje al que se hace referencia en el issue. Compara las comprobaciones del event emitter en las vistas de componentes hermanas mencionadas en el informe y, después, revisa las pruebas pertinentes de Switch o añade cobertura para una vista reciclada si las pruebas existentes revelan este caso. Se considera terminado cuando onChange: gestiona de forma segura un emitter borrado y el comportamiento existente de Switch sigue estando cubierto.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- C++
- Estrellas
- 127k
- Forks
- 25.3k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de react/react-native
-
Linking.getInitialURL() returns the task's first link after a link relaunches a reclaimed Android appPosiblemente ocupada @YevheniiKotyrlo la tomó hace 7 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
react/react-native#59006 · 2 comentarios ·
Los mantenedores suelen responder en 2 días
-
Fabric TextInput: prepareForRecycle leaves stale inputAccessoryViewButtonLabel (empty Done bar)Posiblemente ocupada @jkasprzyk17 la tomó hace 6 días. AbiertoNeeds: Author Feedback Needs: Repro
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
react/react-native#58952 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
[iOS][Fabric] TextInput drops a keystroke right after the first character typed into an empty field (_textOf:equals: compares attributes of a focused field)Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. AbiertoNeeds: Attention Needs: Repro
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
react/react-native#58904 · 3 comentarios ·
Los mantenedores suelen responder en 2 días
-
Needs: Author Feedback Needs: Repro
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
react/react-native#58659 · 2 comentarios ·
Los mantenedores suelen responder en 2 días
-
Needs: Author Feedback Needs: Repro
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
react/react-native#58621 · 1 comentario ·
Los mantenedores suelen responder en 2 días
Todos los issues de react/react-native
Issues similares
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
metasequoiaime/msime#9113 ·
Los mantenedores suelen responder en 1 día
-
Locked plugin flip-flops position on every refresh after being disabledPosiblemente ocupada @Illustar0 la tomó hoy. Abiertoissue report
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
ModOrganizer2/modorganizer#2449 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
Los mantenedores suelen responder en 1 día
-
enhancement P5
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
open-astro/AlpacaBridge#1468 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día