iOS: emitOnBrownfieldMessage: can crash with std::bad_function_call when native posts before JS requires the TurboModule (cold-start race)
Los mantenedores suelen responder en 4 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Tranquilo
- Stack tecnológico
- cpp, ios, objective-c, react-native
- Área
- api, mobile-dev
Línea de trabajo
Comienza en ReactNativeBrownfieldModule.mm con -handleNativeToJSMessage: y +emitMessageFromNative:, y luego sigue emitOnBrownfieldMessage: hasta la inicialización del callback de SpecBase generado. Reproduce o instrumenta un post nativo antes de que JS requiera el TurboModule, y verifica que esta ruta de inicio en frío ya no se bloquee cuando el callback no esté disponible.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
ReactNativeBrownfieldModule.mm's +emitMessageFromNative: only checks that the Obj-C singleton exists before calling emitOnBrownfieldMessage::
+ (void)emitMessageFromNative:(NSString *)message {
if (_sharedInstance) {
[_sharedInstance emitOnBrownfieldMessage:@{ @"text": message }];
} else {
NSLog(@"ReactNativeBrownfieldModule is not initialized, dropping message");
}
}
_sharedInstance is set in -init, which runs as soon as the bridge/TurboModuleManager instantiates the Obj-C module. But the codegen SpecBase's _eventEmitterCallback (the std::function that emitOnBrownfieldMessage: invokes) is only populated inside the C++ SpecJSI constructor, which only runs when getTurboModule: fires — i.e. when JS actually evaluates TurboModuleRegistry.getEnforcing('ReactNativeBrownfield').
If a host app calls ReactNativeBrownfield.shared.postMessage(...) (→ posts BrownfieldMessageToJSNotification → handleNativeToJSMessage: → emitMessageFromNative:) after the Obj-C module exists but before JS has required the module — e.g. right as a hosting view controller's viewDidAppear fires on a cold app launch, racing bundle evaluation — _eventEmitterCallback is still empty, and calling it throws std::bad_function_call, crashing the whole app (uncaught C++ exception).
Confirmed still present on main (4.0.0) as of 2026-07-06 — emitMessageFromNative:'s guard is unchanged from what's below (also reproduced against 3.3.0 in our own app):
- (void)handleNativeToJSMessage:(NSNotification *)notification {
NSString *message = notification.userInfo[@"message"];
if (message) {
[ReactNativeBrownfieldModule emitMessageFromNative:message];
}
}
Suggested fixes
- Wrap the
_eventEmitterCallbackinvocation in a readiness check (or try/catch) inside the generatedemitOnBrownfieldMessage:, or - Expose a callback/promise so host apps can gate native→JS
postMessagecalls on "TurboModule ready" rather than just "bundle loaded" (the closest signalstartReactNative(onBundleLoaded:)currently offers).
Repro
Timing-dependent — we haven't produced a deterministic repro case, but the code path is unambiguous from source, and we hit it in production (Crashlytics, std::__1::bad_function_call: std::exception, 100% of occurrences within the first second of a session). Happy to share a sanitized stack trace if useful.
Environment
@callstack/react-native-brownfield: 3.3.0 (also read againstmain/4.0.0 source)- iOS 26.x, React Native new architecture (TurboModules/Fabric)
- Lenguaje dominante
- TypeScript
- Estrellas
- 552
- Forks
- 53
- Merge medio
- 5 d 9 h
- PR fusionados (30 d)
- 17
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin 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 callstack/react-native-brownfield
-
`package:ios --add-spm-package`: allow project-declared extra XCFrameworks as binary targetsAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
callstack/react-native-brownfield#468 ·
Los mantenedores suelen responder en 4 días
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 38/100
callstack/react-native-brownfield#406 ·
Los mantenedores suelen responder en 4 días
-
Common network layerQuizá libre de nuevo @dratwas la tomó hace 2538 días y no hay ningún pull request abierto. Abierto
callstack/react-native-brownfield#23 · 1 asignado ·
Los mantenedores suelen responder en 4 días
-
Add support for bottom tabsQuizá libre de nuevo @krizzu la tomó hace 2538 días y no hay ningún pull request abierto. Abierto
callstack/react-native-brownfield#22 · 1 asignado ·
Los mantenedores suelen responder en 4 días
-
Tests for libraryAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
callstack/react-native-brownfield#11 · 2 comentarios ·
Los mantenedores suelen responder en 4 días
Todos los issues de callstack/react-native-brownfield
Issues similares
-
submodule-pointer-regression
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
smith-horn/skillsmith#3061 ·
Los mantenedores suelen responder en 1 día
-
area: ops type: test
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
accensa/x402-facilitator-stellar#559 ·
Los mantenedores suelen responder en 1 día
-
Fix the no-pin ruling in line-drawings: pin a below-the-record stage at the record's chapterAbiertodocumentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
cosimochellini/one-piece-zero-spoiler#551 ·
Los mantenedores suelen responder en 1 día
-
getWatched() omits __proto__ directories when cwd is setPosiblemente ocupada @maxazure la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
-
area:web enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día