You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using react-native-firebase for authentication, Realtime Database and Notifications and I am having a bug with realtime events listeners just on iOS it is working fine on Android.
the issue is happening when I kill the app and restart it, when I first install the app the listeners are working and I am getting the updates but once I restart the app the listeners are not firing for updates anymore. I am suspecting that the cleanup is not working properly when I call off on the reference especially when I kill the app on the screen that is starting the listeners.
I tried calling off on the specific listener, by eventType and on all the listeners on the reference but none of them seems to be working.
I also think that it is good to mention that this bug started after I implemented cloud messaging, it used to work properly before that. I also tested different react-native-firebase versions but the bug is always there.
Tested versions: 18.5.0, 18.4.0, 17.5.0 and 17.4.0.
The following is the hook that I am calling in the posts screen.
export function PostListenerHook(challengeId: number) {
const dispatch = useAppDispatch();
useFocusEffect(
useCallback(() => {
const now = moment.utc(new Date()).toDate();
const databaseRef = database().ref(
`/updates/challenges/${challengeId}/mainposts`,
);
const onPostUpdated = databaseRef.on(
'child_changed',
snapshot => {
let updatedPostId = snapshot.key;
if (updatedPostId !== null) {
let postRequest: PostRequest = {
challengeId: challengeId,
postId: Number(updatedPostId),
};
dispatch(checkShouldRefresh(postRequest));
}
},
err => console.log('errror: ', err),
);
const onPostAdded = databaseRef.on(
'child_added',
snapshot => {
let updatedDatetimeUTC = snapshot.val()?.UpdatedDatetimeUTC
? moment.utc(snapshot.val()?.UpdatedDatetimeUTC).toDate()
: undefined;
if (updatedDatetimeUTC && isDateAfter(updatedDatetimeUTC, now)) {
let updatedPostId = snapshot.key;
if (updatedPostId) {
let postRequest: PostRequest = {
challengeId: challengeId,
postId: Number(updatedPostId!),
};
dispatch(getNewPostByIdThunk(postRequest));
}
}
},
err => console.log('errror: ', err),
);
// Stop listening for updates when no longer required
return () => {
console.log('child_changed clenup');
databaseRef.off('child_changed', onPostUpdated);
console.log('child_added clenup: ');
databaseRef.off('child_added', onPostAdded);
// Also tested by event type
databaseRef.off('child_changed');
databaseRef.off('child_added');
// And also tested to remove all listeners on that reference
databaseRef.off();
};
}, [challengeId, dispatch]),
);
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I am using react-native-firebase for authentication, Realtime Database and Notifications and I am having a bug with realtime events listeners just on iOS it is working fine on Android.
the issue is happening when I kill the app and restart it, when I first install the app the listeners are working and I am getting the updates but once I restart the app the listeners are not firing for updates anymore. I am suspecting that the cleanup is not working properly when I call off on the reference especially when I kill the app on the screen that is starting the listeners.
I tried calling off on the specific listener, by eventType and on all the listeners on the reference but none of them seems to be working.
I also think that it is good to mention that this bug started after I implemented cloud messaging, it used to work properly before that. I also tested different react-native-firebase versions but the bug is always there.
Tested versions: 18.5.0, 18.4.0, 17.5.0 and 17.4.0.
The following is the hook that I am calling in the posts screen.
Beta Was this translation helpful? Give feedback.
All reactions