Skip to content

[@react-native-firebase/database] database().ref.on() fires only once after app start. React Native (Android) #8220

Open
@ssobcuk

Description

@ssobcuk

Android only! IOS works fine
My subscrition to database changes ( .on() ) works only once after app start, then callback staying untriggered after changes in database. It starts after React Native uptating to 0.76.5.

If i try get info by .once - everything works perfect and i can get last added item

useEffect(() => {
const onValueChange = database()
.ref(/${MODE}/shops/${user.shop.firebaseUserUid})
.on("value", (snapshot) => {
const value = snapshot.val();
console.log(value, 'value') //fires only once!!!

  });

return () =>
  database()
    .ref(`/${MODE}/shops/${user.shop.firebaseUserUid}`)
    .off("value", onValueChange);

}, []);

package.json

{
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"@react-native-async-storage/async-storage": "^1.17.11",
"@react-native-camera-roll/camera-roll": "^7.8.3",
"@react-native-community/datetimepicker": "^8.2.0",
"@react-native-community/push-notification-ios": "^1.11.0",
"@react-native-firebase/app": "^21.4.0",
"@react-native-firebase/auth": "^21.4.0",
"@react-native-firebase/crashlytics": "^21.4.0",
"@react-native-firebase/database": "21.6.2",
"@react-native-firebase/messaging": "^21.4.0",
"@react-native-picker/picker": "^2.4.8",
"@react-navigation/drawer": "^7.0.1",
"@react-navigation/native": "^7.0.0",
"@react-navigation/stack": "^7.0.0",
"axios": "^0.19.2",
"lodash": "^4.17.19",
"lottie-react-native": "^7.1.0",
"moment": "^2.27.0",
"react": "18.3.1",
"react-native": "0.76.5",
"react-native-animated-input": "^1.0.1",
"react-native-bootsplash": "^6.2.6",
"react-native-calendars": "^1.1293.0",
"react-native-codegen": "^0.70.7",
"react-native-config": "^1.5.3",
"react-native-device-info": "^14.0.0",
"react-native-draggable-flatlist": "^4.0.1",
"react-native-elements": "^3.4.3",
"react-native-email": "^1.1.0",
"react-native-fast-image": "^8.3.4",
"react-native-gesture-handler": "^2.21.2",
"react-native-image-crop-picker": "^0.32.2",
"react-native-image-resizer": "1.4.5",
"react-native-keyboard-aware-scroll-view": "^0.9.5",
"react-native-linear-gradient": "^2.6.2",
"react-native-modal": "^13.0.1",
"react-native-modal-datetime-picker": "^18.0.0",
"react-native-modal-selector": "^2.1.2",
"react-native-permissions": "^2.1.5",
"react-native-push-notification": "^8.1.1",
"react-native-qrcode-svg": "^6.3.12",
"react-native-reanimated": "^3.9.0-rc.1",
"react-native-responsive-screen": "^1.4.1",
"react-native-safe-area-context": "^4.12.0",
"react-native-screens": "^4.3.0",
"react-native-spinkit": "^1.5.1",
"react-native-step-indicator": "^1.0.3",
"react-native-svg": "^15.8.0",
"react-native-swiper": "^1.6.0",
"react-native-vector-icons": "^10.2.0",
"rn-fetch-blob": "0.13.0-beta.2",
"yarn": "^1.22.22"
},
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.3",
"@babel/runtime": "^7.25.0",
"@react-native-community/cli": "15.0.1",
"@react-native-community/cli-platform-android": "15.0.1",
"@react-native-community/cli-platform-ios": "15.0.1",
"@react-native/babel-preset": "0.76.5",
"@react-native/eslint-config": "0.76.5",
"@react-native/metro-config": "0.76.5",
"@react-native/typescript-config": "0.76.5",
"@types/react": "^18.2.6",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.6.3",
"eslint": "^8.19.0",
"jest": "^29.6.3",
"prettier": "2.8.8",
"react-test-renderer": "18.3.1",
"typescript": "5.0.4"
}
}

Describe your issue here


Project Files

Javascript

Click To Expand

package.json:

# N/A

firebase.json for react-native-firebase v6:

# N/A

iOS

Click To Expand

ios/Podfile:

  • I'm not using Pods
  • I'm using Pods and my Podfile looks like:
# N/A

AppDelegate.m:

// N/A


Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->


Environment

Click To Expand

react-native info output:

 OUTPUT GOES HERE
  • Platform that you're experiencing the issue on:
    • iOS
    • Android
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • react-native-firebase version you're using that has this issue:
    • e.g. 5.4.3
  • Firebase module(s) you're using that has the issue:
    • e.g. Instance ID
  • Are you using TypeScript?
    • Y/N & VERSION


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions