Repository navigation
Conversation
…tter is ready emitMessageFromNative: only checked the module singleton. The event emitter callback is set when getTurboModule: builds the JSI spec, so a message posted before JS first requires the module called an empty std::function and threw std::bad_function_call. Drop the message with a log line instead. Fixes callstack#420 Agent: claude
…arly messages The code comment now links the codegen lines and the std::function call operator page for the claims it makes. The Swift, Objective-C and doc comment for postMessage say a message sent before JS loads the Brownfield module is dropped with a log line. Agent: claude
React Native installs the callback on the JS require path, while postMessage delivers on the main queue. Read, install and clear the callback under one lock, clear it on invalidate, and document that the drop log is written only when the module exists but its emitter is not ready. Agent: claude
…tter event Messages can be received using ReactNativeBrownfield.onMessage() (packages/react-native-brownfield/src/index.ts:94-106). Agent: claude
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #420
emitMessageFromNative:only checked that the module singleton exists. React Native sets that singleton ininit(ReactNativeBrownfieldModule.mm:19) and installs the event emitter callback later, ingetTurboModule:(RCTTurboModuleManager.mm#L336-L345), on the JS require path (RCTTurboModuleManager.mm#L845-L860). The callback is a@protectedivar (index.js#L44) that the generated setter assigns (serializeModule.js#L44). A message in that gap calls an emptystd::function, which throwsstd::bad_function_call. Modules needing main-queue setup are created there (RCTTurboModuleManager.mm#L541-L543), so the read and install can race.This PR reads, installs and emits under one lock, and clears the callback in
invalidate, called at teardown (RCTTurboModuleManager.mm#L944-L985). A message sent before the emitter is ready is dropped with a log line; before the module exists, without one.Ran live on f5908f9: the real
ReactNativeBrownfieldModule.mm, built on macOS against a stub codegen base, ran an early message, the JS install, a message, invalidate and a message after teardown, plus a two-thread install and emit loop under ThreadSanitizer. c236f97 throwsstd::bad_function_callon the early message; b28622f reports a race. f5908f9 drops the early message with a log, delivers the later one, delivers nothing after invalidate, and reports no race.Testing:
yarn build,yarn lint,yarn typecheckandyarn test:packagespass on f5908f9. The AppleApp example was built and its Detox E2E (yarn ci:local:appleapp:e2e:ios) passed 5 of 5 on f5908f9, on an Intel Mac withARCHS=x86_64in the Detox build.The
postMessagedocs say messages are received withReactNativeBrownfield.onMessage()(src/index.ts:94-106).AI disclosure: AI-assisted writing and checking, including automated tests and live checks; I take responsibility for it.