fix: [SDK-4342] guard against missing EventEmitter to prevent crash on Old Architecture#1938
Closed
fadi-george wants to merge 2 commits intomainfrom
Closed
Conversation
…n Old Architecture EventManager.setupListeners() now checks whether codegen EventEmitter functions are available before subscribing. This prevents a TypeError crash at import time when the New Architecture is not enabled, allowing all non-event SDK functionality to continue working. Made-with: Cursor
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.
Description
One Line Summary
Add a guard in
EventManager.setupListeners()to prevent a crash when codegen EventEmitter functions are unavailable (Old Architecture).Details
Motivation
Since v5.4.0, the SDK uses
CodegenTypes.EventEmitter(TurboModules) for native events. If a user's app doesn't have the New Architecture enabled,onPermissionChangedand other EventEmitter properties areundefinedon the native module object. BecauseEventManageris constructed at module import time, this causes aTypeErrorcrash that prevents the entire SDK from loading — not just events, but all functions includinginitialize().Reported in #1930
Scope
EventManager.setupListeners()now checkstypeof this.RNOneSignal.onPermissionChanged !== 'function'before subscribing to any emitters.console.erroris logged directing the user to enable New Architecture, and the method returns early.initialize,login,requestPermission, etc.) continues to work normally even without event emitters.Testing
Unit testing
Added a test case verifying that
EventManagerdoes not throw when constructed with a module object that lacks EventEmitter functions, and that the appropriate error message is logged.Manual testing
All 245 unit tests pass. Lint, type checks, and production build (
vp pack) all succeed.Affected code checklist
Checklist
Overview
Testing
Final pass
Made with Cursor