Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[馃敟] Priority values missing from firebase realtime database DataSnapshot #7719

Open
2 of 10 tasks
chetstone opened this issue Apr 1, 2024 · 2 comments
Open
2 of 10 tasks
Labels
Help: Needs Triage Issue needs additional investigation/triaging. Impact: Bug New bug report Workflow: Needs Review Pending feedback or review from a maintainer.

Comments

@chetstone
Copy link

Issue

Describe your issue here

I'm switching my app from firebase web (V8) to react-native-firebase. (I figured it would be less work to refactor than going to web V9) But I have run into a problem.

I use Priority values to store a value that indicates ordering of objects in a realtime database container, and when I read the snapshot the priorities are not there. It seems like the top-level snapshot has a priority value, but when I access the child snapshots with snap.child("child1') or snap.forEach(), the child snapshots do not contain a .priority property.

This is the code has been working in my app for over 5 years (with added debugging printouts).

  subscribeFB() {
      if (!this.unlistenFB) {
        this.unlistenFB = this.user.child('Counternames').on(
          'value',
          (snap) => {
            // Need to also grab the current timestamps when 
            // Counternames changes.
            this.getTimestamps(snap);
          },
          (error) => {
            info('Counternames subscription cancelled because', error);
          }
        );
      }
    }

    getTimestamps(snap) {
      this.user.child('Timestamps').once(
        'value',
        (tsSnap) => {
          setTimeout(
            () =>
              MultiActions.setCounters({
                counterSnap: snap,
                timestamps: tsSnap.val(),
              }),
            0
          );
        },
        (error) => {
          info('Could not get timestamps because', error);
        }
      );
    }
// Then in setCounters I use both snaps

 setCounters(snaps) {
  [...]
       if ( timestamps.sequence > this.state.timestamps.sequence) {
          debug('Getting new sequence from FB');
          // get sequence from FB
          var CounternameSnap = snaps.counterSnap;
          var cns = CounternameSnap.exportVal();
          debug(`CounternameSnap exportVal ${JSON.stringify(cns, null, 2)}`);

          var ch = CounternameSnap.child('-MH3NnGU5iM0eakrd7ZS').exportVal();
          debug(`Counter 44 exportVal ${JSON.stringify(ch)}`);

          CounternameSnap.forEach((ctr) => {
            var p = ctr.getPriority();

            debug(`Counter priority ${p} has key ${ctr.key}, val ${ctr.val()}`);
            // Do something with priority...
          });
 

When I change the order of the counters on another device, my .on listener triggers and I get the following printout:

 LOG  MultiStore:debug Getting new sequence from FB +2ms
 LOG  MultiStore:debug CounternameSnap exportVal {
  ".value": {
    "-MH3MqLK32gCi0pqBUg3": "Counter 33",
    "-MH4yucF8rmeewGbPAVI": "Counter 55",
    "-MH3NnGU5iM0eakrd7ZS": "Counter 44",
    "-NuBYkNVlAUIUeoQQCKA": "Counter 66",
    "-MGQOBLgEvEekOg6geQI": "Counter 11",
    "-MGzzZXdUwpBr8RlLLE-": "Counter 22"
  },
  ".priority": null
} +1ms
 LOG  MultiStore:debug Counter 44 exportVal {".value":"Counter 44"} +1ms
 LOG  MultiStore:debug Counter priority undefined has key -MGzzZXdUwpBr8RlLLE-, val Counter 22 +2ms
 LOG  MultiStore:debug Counter priority undefined has key -MH4yucF8rmeewGbPAVI, val Counter 55 +1ms
 LOG  MultiStore:debug Counter priority undefined has key -MH3NnGU5iM0eakrd7ZS, val Counter 44 +1ms
 LOG  MultiStore:debug Counter priority undefined has key -MH3MqLK32gCi0pqBUg3, val Counter 33 +0ms
 LOG  MultiStore:debug Counter priority undefined has key -MGQOBLgEvEekOg6geQI, val Counter 11 +1ms
 LOG  MultiStore:debug Counter priority undefined has key -NuBYkNVlAUIUeoQQCKA, val Counter 66 +1ms

This shows the top-level snap contains a .priority value (null) but the "Counter 44" child does not have the property at all. I can verify that the other device successfully pushed the new priorities to firebase: although the firebase console does not show priorities, I can export and download the container, and it looks like this:

{
  "-MGQOBLgEvEekOg6geQI": {
    ".value": "Counter 11",
    ".priority": 4
  },
  "-MGzzZXdUwpBr8RlLLE-": {
    ".value": "Counter 22",
    ".priority": 0
  },
  "-MH3MqLK32gCi0pqBUg3": {
    ".value": "Counter 33",
    ".priority": 1
  },
  "-MH3NnGU5iM0eakrd7ZS": {
    ".value": "Counter 44",
    ".priority": 2
  },
  "-MH4yucF8rmeewGbPAVI": {
    ".value": "Counter 55",
    ".priority": 3
  },
  "-NuBYkNVlAUIUeoQQCKA": {
    ".value": "Counter 66",
    ".priority": 5
  }
}

Is this exposing a previously unknown bug in my program, is it a bug in RNFirebase, a change in underlying FB V9+ iOS/Android libraries (It has the same problem on both platforms), or ???

react-native: 0.70.15

react-native-firebase: 19.1.1

[UPDATE:] I wondered if offline persistence might have something to do with this so I enabled persistence and found the problem remains the same either way.

[NOTE:] I filed a StackOverflow question about this but since I'm pretty sure this is a bug I decided to go ahead and file an issue. The above is a copy-paste from that SO question.

I created a reproducible demo which is here.
This is the RNFB demo with just App.tsx changed to demonstrate the issue. Since the whole setup is the default, I have not included any of my own files below (Podfile, build.gradle, etc.) Note that I only tried the RNFB demo on iOS but I have confirmed the issue is the same on Android in my app.

When running my demo, you may want to edit make-demo.sh so it doesn't install all the RNFB modules. The only ones needed are app and database. Also, the default react-native run-ios build fails for me. I didn't investigate, I always prefer to use xcode. I just opened up xcode and ran on the simulator with no problem


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:

info Fetching system and libraries information...
System:
  OS: macOS 14.3.1
  CPU: (8) arm64 Apple M1 Pro
  Memory: 86.19 MB / 16.00 GB
  Shell:
    version: 3.2.57
    path: /bin/bash
Binaries:
  Node:
    version: 20.11.1
    path: ~/.nodenv/versions/20.11.1/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.2.4
    path: ~/.nodenv/versions/20.11.1/bin/npm
  Watchman:
    version: 2022.11.28.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.1
    path: /Users/chet/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - visionOS 1.0
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.1 AI-221.6008.13.2211.9514443
  Xcode:
    version: 15.2/15C500b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.18
    path: /usr/bin/javac
  Ruby:
    version: 2.7.7
    path: /Users/chet/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.6
    wanted: 0.73.6
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

  • 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:
    • 19.1.1
  • Firebase module(s) you're using that has the issue:
    • database
  • Are you using TypeScript?
    • N & VERSION


@chetstone chetstone added Help: Needs Triage Issue needs additional investigation/triaging. Impact: Bug New bug report labels Apr 1, 2024
@mikehardy mikehardy added the Workflow: Needs Review Pending feedback or review from a maintainer. label Apr 3, 2024
@mikehardy
Copy link
Collaborator

This does look like a bug here - I've marked it for examination

That said, the modular API is already implemented in react-native-firebase and the v8 API should be considered deprecated in all cases, in all ecosystems - so using react-native-firebase for what is sort of an "extended bridge" to continue using the deprecated v8 / non-modular API is technically possible but also not technically advisable

Having ported a few applications to the new style API, I can say it is almost completely mechanical. It's really just a matter of switching up the imports to import the functions (not just the desired module...) then doing a getAuth (or getApp or getNNN) first then just sending it in to the functions - but all the functions behave the same so it's just text moving around, not really functional change. Much easier than I personally feared at least

@chetstone
Copy link
Author

Thanks Mike for looking at this. And thanks for the reassurance about switching to V9. I've noticed that things never turn out as bad as I fear (or as good as I hope :-)

I think I'll bite the bullet and do the switcheroo. It might take a while to fix this one in RNFB. I tried looking for low-hanging fruit-- I cloned and built your repo (Great build system: I was surprised it was so easy to build such a large project and run the tests). I wrote a test case and found the line in DatabaseDataSnapshot.js where it looked like priority was not being copied into the new snap. chetstone/react-native-firebase@main...chetstone:react-native-firebase:tryfix7719

But it didn't work.
So the problem may be in native code (though it's strange that it would affect both platforms.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help: Needs Triage Issue needs additional investigation/triaging. Impact: Bug New bug report Workflow: Needs Review Pending feedback or review from a maintainer.
Projects
None yet
Development

No branches or pull requests

2 participants