Skip to content

value events not firing properly when offline #1314

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
k1r0s opened this issue Oct 18, 2018 · 5 comments
Closed

value events not firing properly when offline #1314

k1r0s opened this issue Oct 18, 2018 · 5 comments

Comments

@k1r0s
Copy link

k1r0s commented Oct 18, 2018

From docs: https://firebase.google.com/docs/database/web/read-and-write#listen_for_value_events
related with offline capabilities: #17

image

[REQUIRED] Describe the problem

Value events should fire when ever a change occurs within the whole path. This is supposed to work offline as well, and it does! but not in the same way:

Steps to reproduce:

for example:

{ "todos": {
    "0001": { "text": "something", "uid": "0001" },
    "0002": { "text": "dumy", "uid": "0002" },
    "0003": { "text": "some text", "uid": "0003" }
  }
}

listening for event values on root ("todos"): ref('todos').on('value', f)

f should be called when:

  1. pushing a new reference to the collection: ref('todos').push({ "text": "a" })
  2. replacing the whole collection: ref('todos').set(..)

however offline. f only gets called when change occur directly on the explicit updated spot.

For example if I'm listening with: ref('todos').on('value', f) and I go offline case 2 works but case 1 does not.

Relevant Code:

  • online
ref('todos').on('value', f)
ref('todos').push({ foo: 2 })
ref('todos').set({ bar: 1 })

f should be called twice

  • offline
ref('todos').on('value', f)
ref('todos').push({ foo: 2 })
ref('todos').set({ bar: 1 })

f should be called twic, but gets called once (by set trigger)

[REQUIRED] Describe your environment

  • Operating System version: Linux k1r0s-N2x0WU 4.15.0-36-generic signInWithCustomToken - auth/invalid-api-key #39~16.04.1-Ubuntu SMP Tue Sep 25 08:59:23 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Browser version: Chromium Version 69.0.3497.81 (Official Build) Built on Ubuntu , running on Ubuntu 16.04 (64-bit)
  • Firebase SDK version: "firebase": "^5.5.4"
  • Firebase Product: database
@google-oss-bot
Copy link
Contributor

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@mikelehen
Copy link
Contributor

This is a subtle but expected behavior. The Firebase Realtime Database SDK attempts never to raise 'value' events with partial data. In your example, push() will create a child underneath /todos, but since the SDK doesn't have the rest of the data for the /todos/ location, it can't raise a proper value event containing the entire /values/ location.

If you were to add your 'value' listener and wait for an initial event (even if it's empty) before going offline, then the subsequent push() call would generate an event since the SDK has complete data for /todos/.

In your case, you may find that listening to child_added, child_changed, and child_removed events will meet your needs better. If you had a 'child_added' listener instead of 'value', then it would fire for your push() call, even while offline, since we'd have complete data for the added child.

Hope this helps.

@k1r0s
Copy link
Author

k1r0s commented Oct 20, 2018

Mmmm yeah..well

@k1r0s
Copy link
Author

k1r0s commented Oct 20, 2018

I get the point

@k1r0s
Copy link
Author

k1r0s commented Oct 20, 2018

Thanks

@firebase firebase locked and limited conversation to collaborators Oct 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants