-
Notifications
You must be signed in to change notification settings - Fork 142
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
<firebase-query>
sometimes return 2 sets of expected data on v2.2.0
#263
Comments
@andrewspy thanks for the headsup but can you give us on at least a working code we can copy or fork on? Thanks |
Hmmmm... wait... I think I know this because I tried to replicate firebase-query on a project and tried to fix it. Lemme check the code |
I can't seem to replicate it even given this code:
You can try giving us a sample, but it might be a race condition between firebaseOnValue and firebaseOnChildAdded |
@tjmonsi Sorry for the late reply, it's a rather straight forward code as per your sample, but I am using the same I'll try to reproduce it and provide a sample code later today. |
Yes please :) Thanks |
@tjmonsi Here's the test case as promised, the problem occurs when you stamp the <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Polymer Element Test Case</title>
<script src="./bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="./bower_components/polymer/polymer.html">
<link rel="import" href="./bower_components/polymerfire/firebase-app.html">
<link rel="import" href="./bower_components/polymerfire/firebase-query.html">
<link rel="import" href="my-query.html">
</head>
<body>
<h1>Duplicate firebase-query result</h1>
<!-- Test case HTML goes here -->
<firebase-app
api-key="xxx"
auth-domain="xxx"
database-url="https://xxx.firebaseio.com"
storage-bucket="xxx.appspot.com"
messaging-sender-id="xxx">
</firebase-app>
<button onclick="addQuery()">Add Query</button>
<script>
function addQuery() {
let newQuery = document.createElement("my-query");
document.body.appendChild(newQuery);
};
</script>
</body>
</html> and here's the code for <dom-module id="my-query">
<template>
<style>
:host {
display: block;
}
</style>
<firebase-query log
path="/test"
data="{{data}}">
</firebase-query>
<p>
[my-query]
<template is="dom-repeat" items="[[data]]">
[[item.value]]
</template>
</p>
</template>
<script>
Polymer({
is: 'my-query'
});
</script>
</dom-module> Thanks for looking into the issue urgently! |
Thanks I'll check this up after my errands |
it seem like this is an issue from #170 😭 |
Hi guys, I have checked the firebase behavior and it is a race condition. Somehow this happens:
When you add new-query via dynamic event (like on-click)
See that before loading data to browser from firebase the event call was:
When data is in browser
Quick fix is to have a check on both on-value and on-child-added to check if the key is already existing in the data array, so duplicates will not be added. But long term fix, I'm still thinking. Might be going to do a PR later this week (need to finish something for community and work). @mbleigh or others might want to take a look at this You can download a working repo to see the behavior: https://github.com/tjmonsi/polymerfire-fixers/tree/master/issue-263 |
@tjmonsi Just to share that the problem affect both polymer v1.9 and v2.0, so it may not be a polymer-v2 only issue. |
Not 100% sure if this is a good fix or not. /* Now let child_added deal with subsequent changes */
setTimeout(()=>{
this.query.off('value', this.__onFirebaseValue, this);
this.__initialLoadDone = true;
}, 0);
},``` |
I don't think that's the best fix, given that it is more hackish in a way that we are just "pushed" it to the last of the event stack but it is still unpredictable in terms of race conditions. One thing I can think of this will fail is this: on-value is called (for 3 children)
we added setTimeout to turn off on-value and setting __initialLoadDone to true, adding another event in the event queue: We call on-child-added 3 times without duplicating values because __initialLoadDone is still false (yey) Running on-child-added of new data but not putting it because __initialLoadDone is not yet added on-value is again called and add another event for turning off on-value (running number 4) Running turn off on-value twice. Yes, it might return 4 items, but that's a lot of function calls. What I think is best in this case is that,
|
Ya felt that way too, it worked but would mess with the network load scenario. |
It is still unpredictable though. :( I'll create PR and let you guys see if it's ok |
@tjmonsi - just curious (and also soon releasing an app to production ...), do you have any planned date for a new PR for this ? |
@christophe-g working on it this weekend. |
@christophe-g I have time just now. You guys can check: #270 |
@tjmonsi The fix doesn't work with the test case I submitted above #263 (comment), as it always returns 2 sets of expected results now. On my project, it also breaks some of my other |
@andrewspy did you manage to use my branch? I'm going to check it again tonight |
I see it now. Going for a fix |
@andrewspy & @tbeattysk - added a fix. I think it was because I was still awake by 1am? But then again... |
Description
<firebase-query>
sometimes return 2 sets of expected data on v2.2.0. It was working fine with v2.1.x.Expected outcome
data
return a set of expected data.Actual outcome
data
return 2 sets of expected dataLive Demo
N/A
Steps to reproduce
You may need to use
<firebase-query>
more than once to reproduce.Browsers Affected
The text was updated successfully, but these errors were encountered: