On the first load of the page after a user login event, I want to populate the items property with a set of objects stored in my Firebase.
A achieves my desired behavior.
A<firebase-query
id="query"
...
path="users/[[user.uid]]/widgets"
data="{{items}}">
</firebase-query>
B does not.
B<firebase-query
id="query"
...
path="widgets"
data="{{items}}">
</firebase-query>
When using B, I expect to see the items object populate, but instead the items object is null. However, if I refresh the browser manually (without logging out) the element behaves as expected. However, if I log out (then refresh while logged out), the problem reappears until I reload again. If I only log out then log back in the problem does not reappear due, I think, in part to the fact the app does not reset as described here.
Why does A work? But not B? And what modifications must I make to B to get it to work? (Because I want to store the widgets from the root/widgets/ path and not have to store that detail under the users/... path.
Previous Unsuccessful Attempts
My current (unproven) theory is that the in the case of B (when the URL is constant/static, i.e., widgets/) firebase-query gets involved in some sort of race condition; and only fetches the data after some lifecycle event and doesn't attempt to re-fetch the data. On the other hand, the firebase-query does attempt to re-fetch when the path is dynamically updated based on the databinding in the path attribute (i.e., path="users/[[user.uid]]/widgets"). Is this theory correct? Or is there some other cause? Do I need to imperatively fetch the data after some event? If so, how can I accomplish all this?
I have tried the following ideas without success.
Cuser: {
type: Object,
notify: true,
observer: '_userChanged',
},
_userChanged: function() {
this.$.query.path = 'widgets';
var items = this.$.query.ref.child('widgets');
this.set('items', items);
},
D
<firebase-query
id="query"
...
path="[[path]]"
data="{{items}}">
</firebase-query>
<script>
...
properties: {
path: {
type: String,
value: function() {
return 'widgets';
},
}
},
...
</script>
Also, on the Polymer Slack Site, @will-in-china says:
I have had problems with the data loading the first time, I found that if i don't have more than one reference to the same path, i dont get this issue.
I'm not sure what that means in this context as I only have one reference in my element (and app) to the path path="widgets" inside a firebase-query element.