expo: Expo Notifications crashes app on reload
Summary
Expo Notifications 0.14.0 will crash an expo-dev-client build on an Ios device on app reload.
- Open the app on the device.
- Hit “r” in the terminal.
The app will crash with…
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error when sending event: onDevicePushToken with body: {
devicePushToken = ***ACTUAL TOKEN REMOVED***;
}. Bridge is not set. This is probably because you've explicitly synthesized the bridge in EXReactNativeEventEmitter, even though it's inherited from RCTEventEmitter.'
The app does not crash when using Expo Go.
Somewhat similar issue. https://github.com/expo/expo/issues/3276
Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!
managed
What platform(s) does this occur on?
iOS
SDK Version (managed workflow only)
44
Environment
Expo CLI 5.0.3 environment info: System: OS: macOS 12.1 Shell: 5.8 - /bin/zsh Binaries: Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.0/bin/yarn npm: 8.3.0 - ~/.nvm/versions/node/v16.13.0/bin/npm Managers: CocoaPods: 1.11.2 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3 IDEs: Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild npmPackages: expo: ~44.0.0 => 44.0.3 react: 17.0.1 => 17.0.1 react-dom: 17.0.1 => 17.0.1 react-native: 0.64.3 => 0.64.3 react-native-web: 0.17.1 => 0.17.1 npmGlobalPackages: eas-cli: 0.43.0 expo-cli: 5.0.3 Expo Workflow: managed
Reproducible demo
import {View} from 'react-native';
import {useEffect} from 'react';
import * as Notifications from 'expo-notifications';
export default function App() {
useEffect(() => {
const subscription = Notifications.addNotificationResponseReceivedListener(response => {});
return () => subscription.remove();
}, []);
return <View />
}
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 30
- Comments: 40 (12 by maintainers)
Commits related to this issue
- [core][iOS] Fix modules have not been deallocated on the reload (#17285) # Why Closes https://github.com/expo/expo/issues/15788. Right now, modules have not been deallocated on the reload. # H... — committed to expo/expo by lukmccall 2 years ago
- [core][iOS] Fix modules have not been deallocated on the reload (#17285) Closes https://github.com/expo/expo/issues/15788. Right now, modules have not been deallocated on the reload. Remove cycle re... — committed to expo/expo by lukmccall 2 years ago
- [core][iOS] Fix modules have not been deallocated on the reload (#17285) Closes https://github.com/expo/expo/issues/15788. Right now, modules have not been deallocated on the reload. Remove cycle re... — committed to expo/expo by lukmccall 2 years ago
Did some digging, found that this line leads to crash on dev client reloads. This line is calling
registerForRemoteNotificationson the native side which emits event to JS side at some point. This assertion is crashing the app.Attaching some logs when it crashes. It tries to send the event but the bridge is not set. I am not sure why the bridge could be nil, maybe some race condition, will have to dig more 😅
Just importing
import * as Notifications from 'expo-notifications';is enough for my app to crash with this error.It got finally assigned to a dev, guess it will be fixed soon 😃
I dont understand why expo is not addressing this issue. It is really frustrating developer experience not being able to reload ios devices. It has been there for 4 months. It seriously kills the will to develop
I solved it by replacing all
expo-notificationsimports with this (which just mocksexpo-notificationsfor iOS in dev-mode):./expo-notifications.js
Just save it as a file locally and import from this instead of directly from
expo-notifications. It mocks it specifically for iOS in dev mode so it doesn’t crash (but is also obviously not usable) - in all other cases it usesexpo-notificationsas usual. Hope this can help someone until it’s fixed! 👍still an issue with the latest versions of
expo-notifications(0.14.1) andexpo-dev-client(0.8.4)hang tight, or look at https://github.com/expo/expo/issues/15788#issuecomment-1099072403 and possibly try applying that suggestion to your project
I am also having this issue on iOS using the dev client.
ah yeah i mean it’s just do not import if on iOS and
__DEV__Seems to be fixed in 0.14.1 Edit: it’s not fixed.
@hirbod good point! I found the issue, that was on our side. Thank you! It works in production
Just to verify that, this exactly is the same problem which occurs only after the reload, but for me it is about
onHandleNotificationprobably because I’m not usingonDevicePushTokenso yeah this is the same issue.And it’s really serious!