> react-native info
OS: Windows 10
Node: 8.9.4
npm: 6.1.0
Packages: (wanted => installed)
react: ^16.3.2 => 16.4.1
react-native: ^0.55.3 => 0.55.3
```json
// package.json
{
"dependencies": {
"react": "^16.3.2",
"react-native": "^0.55.3",
"react-native-firebase": "^4.3.6",
"react-native-google-signin": "^1.0.0-rc5",
"react-navigation": "^2.14.2",
"react-redux": "^5.0.7",
"redux": "^4.0.0",
"redux-thunk": "^2.3.0"
}
}
// /android/app/build.gradle
dependencies {
implementation(project(':react-native-firebase')) {
transitive = false
}
implementation('com.crashlytics.sdk.android:crashlytics:2.9.3@aar') {
transitive = true
}
// RNFirebase required dependencies
implementation "com.google.firebase:firebase-core:16.0.3"
implementation "com.google.android.gms:play-services-base:15.0.1"
// RNFirebase optional dependencies
implementation "com.google.firebase:firebase-ads:15.0.1"
implementation "com.google.firebase:firebase-auth:16.0.3"
implementation "com.google.firebase:firebase-config:16.0.0"
implementation "com.google.firebase:firebase-crash:16.2.0"
implementation "com.google.firebase:firebase-database:16.0.2"
implementation "com.google.firebase:firebase-firestore:17.1.0"
implementation "com.google.firebase:firebase-functions:16.1.0"
implementation "com.google.firebase:firebase-invites:16.0.3"
implementation "com.google.firebase:firebase-storage:16.0.2"
implementation "com.google.firebase:firebase-messaging:17.3.1"
implementation "com.google.firebase:firebase-perf:16.1.0"
implementation "com.facebook.react:react-native:+"
implementation "com.android.support:appcompat-v7:27.1.1"
implementation 'com.android.support:support-annotations:27.1.1'
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From node_modules
implementation(project(":react-native-google-signin")){
exclude group: "com.google.android.gms" // very important
}
implementation 'com.google.android.gms:play-services-auth:16.0.0'
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
I'm on an **Android**, **Connected Device**, with **Live Reload enabled**
I use Firebase for **Auth** and **Realtime Database**
**After Live Reload fires** (each time I save a file, basically), `firebase.database().ref().on()` **stops working.**
Here is my code:
I have a Redux Action to retrieve datas from the logged user
```javascript
// AppRedux.js
const reducer = (state = initialState, action) => {
switch (action.type) {
case 'setCurrentUser':
return { ...state, currentUser: action.value }
break;
// { ... }
}
}
const store = createStore(reducer, applyMiddleware(thunkMiddleware))
export { store }
const setCurrentUser = (user) => {
return {
type: "setCurrentUser",
value: user
}
}
const watchUserData = () => {
return function(dispatch) {
const { currentUser } = firebase.auth()
if (currentUser) {
console.log(currentUser.uid) // I always have the right uid, so firebase.auth() always works
const ref = firebase.database().ref('users/' + currentUser.uid)
ref.on('value', (snapshot) => {
const user = snapshot.val()
console.log(user) // I get there only once !
dispatch(setCurrentUser(user))
}, (error) => {
console.log(error)
})
}
}
}
export { setCurrentUser, watchUserData }
And I call this action in a pretty simple Component (screen)
// Main.js
// { ... other imports}
import { watchUserData } from '../redux/AppRedux'
const mapStateToProps = (state) => {
return {
currentUser: state.currentUser
}
}
const mapDispatchToProps = (dispatch) => {
return {
watchUserData: () => dispatch(watchUserData())
}
}
class Main extends React.Component {
constructor(props) {
super(props)
}
componentWillMount() {
this.props.watchUserData()
}
render() {
const { currentUser } = this.props
return (
<View>
<Text>Hello { currentUser && currentUser.firstname }!</Text>
</View>
)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Main)
This piece of code works perfectly.. only once. When Live Reload fires, it won't work anymore.
Note that firebase.auth()
still works and gives me the right uid
, but firebase.database().ref('users/' + currentUser.uid).on('value')
won't fire anymore, _even if I sign out then sign in again_.
Also note that it works perfectly with Hot Reloading whereas it doesn't with Live Reloading.
I have to npm run android
(which is equal to react-native run-android
) for it to fire again.. until the next Live Reload.
@Ehesp
I think it related to AsyncTask.execute with default THREAD_POOL_EXECUTOR, after restart js code native part not clearing created listener tasks, what you think it can be true ?
Same issue is happening with me after updating to react native 0.57.1. For me even hot reloading stops giving data from firebase.on
@barbarosh what version of RNFB are you on? Are you able to try v5 - published today: https://invertase.link/rnfb-v5
Even code push mandatory update is doing the same. So I can't do code push to my production app . Listeners are not working somehow. I tried to put log in native code. As you can see from below logs value event listeners doesn't trigger ondatachange after codepush or hot reload.
Please help.
Ok thanks, I have a rough idea now what it could be, will take a look today
Hey all, could someone locally apply the PR I just sent up and let me know the result - thanks 馃憤
Loving react-native-firebase
and the support we provide? Please consider supporting us with any of the below:
React Native Firebase
and Invertase
on Twitter @Salakar It doesn't seem to have an effect on my side
// package.json
"react": "^16.5.0",
"react-native": "^0.57.0",
"react-native-firebase": "^5.0.0", // I did manually change the modified files
// build.gradle
implementation "com.google.firebase:firebase-core:16.0.3"
implementation "com.google.firebase:firebase-database:16.0.2"
@Salakar It doesn't seem to have an effect on my side
// package.json "react": "^16.5.0", "react-native": "^0.57.0", "react-native-firebase": "^5.0.0", // I did manually change the modified files
// build.gradle implementation "com.google.firebase:firebase-core:16.0.3" implementation "com.google.firebase:firebase-database:16.0.2"
Daft question sorry 馃檲 but just to double check, did you re-build and re-install the APK after making the changes?
Could you add some logging in the onHostDestroy method and inside the iterators
@Salakar I don't think the fix worked. After hot reloading it still doesn't gives you data.
I tried to put log in onHostDestroy method, nothing is getting logged. So most probably onHostDestroy in not getting called.
To reproduce issue you will have to do Hot reload and all listeners would stop giving data.
@Salakar Could this issue be related to #1407 ? I believe it might be the same
Having the same issue here with:
[email protected]
[email protected]
[email protected]
Same here aswell. However it seems that it doesn't matter whether I use live reload or not. Same issue with live reload disabled and reloading app manually
// package.json
"react": "^16.5.0",
"react-native": "^0.57.1",
"react-native-firebase": "^5.0.0",
//app/build.gradle
implementation "com.google.firebase:firebase-core:16.0.3"
implementation "com.google.firebase:firebase-auth:16.0.3"
implementation "com.google.firebase:firebase-database:16.0.2"
Same to me with (i try to patch according to #1535 but doesn works)
// package.json
"react": "16.5.0",
"react-native": "0.57.2",
"react-native-firebase": "^5.0.0",
//app/build.gradle
implementation "com.google.firebase:firebase-core:16.0.3"
implementation "com.google.firebase:firebase-auth:16.0.3"
implementation "com.google.firebase:firebase-database:16.0.2"
Thanks to the stack trace provided by @guidotajjan in #1601 I think I know what the cause is now will re-attempt a fix today/tomorrow 馃憤
I think the pr doesn't solve this problem.
Things i did :
Still got the same messages on android logcat :
W/MessageQueue: Handler (android.os.Handler) {12abbd8} sending message to a Handler on a dead thread
java.lang.IllegalStateException: Handler (android.os.Handler) {12abbd8} sending message to a Handler on a dead thread
at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)
at android.os.Handler.enqueueMessage(Handler.java:631)
at android.os.Handler.sendMessageAtTime(Handler.java:600)
at android.os.Handler.sendMessageDelayed(Handler.java:570)
at android.os.Handler.post(Handler.java:326)
at com.google.firebase.database.zza.zza(com.google.firebase:firebase-database@@16.0.2:1029)
at com.google.firebase.database.obfuscated.zzcd.zza(com.google.firebase:firebase-database@@16.0.2:47)
at com.google.firebase.database.obfuscated.zzab.zza(com.google.firebase:firebase-database@@16.0.2:286)
at com.google.firebase.database.obfuscated.zzab.zza(com.google.firebase:firebase-database@@16.0.2:346)
at com.google.firebase.database.obfuscated.zzk.zza(com.google.firebase:firebase-database@@16.0.2:5782)
at com.google.firebase.database.obfuscated.zze.zza(com.google.firebase:firebase-database@@16.0.2:2164)
at com.google.firebase.database.obfuscated.zzn.zza(com.google.firebase:firebase-database@@16.0.2:256)
at com.google.firebase.database.obfuscated.zzn.zza(com.google.firebase:firebase-database@@16.0.2:5303)
at com.google.firebase.database.obfuscated.zzn$zzc$2.run(com.google.firebase:firebase-database@@16.0.2:86)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:154)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
@FinCendikia what RN version are you on - I'm unable to reproduce this when using the PR + RN 57.x
@Salakar I'm using
"react": "16.6.0-alpha.8af6728",
"react-native": "0.57.1",
"react-native-firebase": "^5.0.0" + PR,
Everything works fine until the reload.
I have the same problem, with the difference that I'm using Firestore
Hey @Raullg98, thanks for the heads up, I will do the same for Firestore next once I can confirm the fix for DB is working 馃
Guys using these versions of firebase deps in my build.gradle file solved the issue.
implementation "com.google.firebase:firebase-core:16.0.3"
implementation "com.google.firebase:firebase-auth:16.0.3"
implementation "com.google.firebase:firebase-firestore:17.1.0"
implementation "com.google.firebase:firebase-functions:16.1.0"
implementation "com.google.firebase:firebase-messaging:17.3.2"
implementation 'me.leolin:ShortcutBadger:1.1.21@aar' // Support badges
implementation "com.google.firebase:firebase-database:16.0.2"
implementation "com.google.firebase:firebase-invites:16.0.3"
implementation "com.google.firebase:firebase-storage:16.0.2"
with
"react-native": "^0.57.3"
"react-native-firebase": "^5.0.0",
"react": "^16.6.0-alpha.8af6728"
@ruvice117 I have the same issue even with the dependencies you listed.
I can update await firebase.database().ref().update(updates)
, but as soon as I trigger a live reload, it does not work anymore.
any fix to this problem yet? Very significant issue.
All, I've tested #1619 and this is definitely working as a fix for RN reload issues, you can see the test suites for reloading here: https://github.com/invertase/react-native-firebase/pull/1619/commits/2cf778b76aad0080d65b1cc4247d53e8cb1c9001
If I'm missing a test case then let me know (tag me here or ping me on discord), otherwise, I think this is resolved and ready for v5.1.0.
You can give it a go now on the [email protected]
release - see the rc1
release notes on GitHub for the correct Firebase Native SDK versions.
Thanks 鉂わ笍
Loving react-native-firebase
and the support we provide? Please consider supporting us with any of the below:
React Native Firebase
and Invertase
on Twitter Hello!
Forgive me if it's a dumb question, I'm very new to React Native. To get the fix would I need to update my package.json file to look like this: "react-native-firebase": "^5.1.0-rc2"?
Also, any idea on when 5.1.0 will be out?
@HomeSchoolDev 5.1.0 is out now: https://github.com/invertase/react-native-firebase/releases :)
@Ehesp My mistake for missing that. Thank you! :)
Using 5.1.0 here and still seeing the issue.
I have problems with firebase.auth().onAuthStateChanged callbacks & live reload.
After live reload onAuthStateChanged won't fire
@olegwn hi what platform? Could you make an issue with the details and tag me in it - thanks
@Salakar this has been fixed in 5.2.0 release, I no longer see the issue
I am also seeing this issue on [email protected]
. It loads fine the first time, as soon as i reload the app it dosnt work. If I re-install the app then it works fine until reloaded.
implementation "com.google.android.gms:play-services-base:16.0.1"
implementation "com.google.firebase:firebase-core:16.0.3"
implementation "com.google.firebase:firebase-messaging:17.3.2"
implementation "com.google.firebase:firebase-database:16.0.2"
implementation "com.google.firebase:firebase-auth:16.0.3"
Ignore me, I downgraded to 5.2.0
and updated the deps as of the upgrade documentation and its now working (so far anyway)
@danwoodbury @olegwn
I also downgraded mine from 5.2.2
back to 5.2.0
and it's now back to normal.
Thanks
Ignore me, I downgraded to
5.2.0
and updated the deps as of the upgrade documentation and its now working (so far anyway)
This worked for me as well, thanks!
This is still happening for me in 5.3.1
. Downgrading to 5.2.0
fixed it, but will the regression be fixed for upcoming builds?
Don't know if it's useful or not (sorry if it's not!), but it still happens for me on 5.5.6
. Any update for this fix? I'm using firebase database
the problems is that the off if never called when user close app (in my case)
a estupid temporaly solution is something like this
firebase.database().ref('nodo').off();
setTimeout(async () => {
firebase.database().ref('nodo').on(snap => {
//aca tu codigo
})
}
y try to add a await to off and use callback but didn't work
I am facing the same issue with firebase-firestore v5.5.6
. Please suggest any workaround. @Salakar
The v5.x.x branch is in maintenance mode now, if this can't be reproduced on v6 it is unlikely to gain attention, and any attention it will receive will be for that branch. I'm the one doing v5 releases and I only have time to integrate community fixes, so any fix for it will need to be proposed by someone else, then I'll shepherd it to release. The linked PRs here and/or an examination of the diffs from 5.2.0 to 5.2.2 should probably show the way
I'm still facing it. v6.3.4
Update: Upgraded to 6.7.1 and still ref().on() fires once (snapsot.val() is null).
Most helpful comment
Ignore me, I downgraded to
5.2.0
and updated the deps as of the upgrade documentation and its now working (so far anyway)