InstagramClone icon indicating copy to clipboard operation
InstagramClone copied to clipboard

Possible Unhandled Promise Rejection when trying to render the Feed

Open coding-st opened this issue 4 years ago • 6 comments

Hi,

I'm getting the following error when opening the Feed Screen:

Possible Unhandled Promise Rejection (id: 0): TypeError: undefined is not an object (evaluating 'snapshot.query.EP.path')

The Feed also won't render because of that. The code line which produces the error is in the action index.js the const ui:

export function fetchUsersFollowingPosts(uid) {
    return ((dispatch, getState) => {
        firebase.firestore()
            .collection("posts")
            .doc(uid)
            .collection("userPosts")
            .orderBy("creation", "asc")
            .get()
            .then((snapshot) => {
                const uid = snapshot.query.EP.path.segments[1];
                const user = getState().usersState.users.find(el => el.uid === uid);
                let posts = snapshot.docs.map(doc => {
                    const data = doc.data();
                    const id = doc.id;
                    return { id, ...data, user }
                })

                for(let i = 0; i< posts.length; i++){
                    dispatch(fetchUsersFollowingLikes(uid, posts[i].id))
                }
                dispatch({ type: USERS_POSTS_STATE_CHANGE, posts, uid })

            })
    })
}

Can anybody support?

coding-st avatar Jan 26 '21 17:01 coding-st

Hi @coding-st !

Thank you for your participation.

I'll be reviewing that bug and I'll try to push out a fix for it asap :)

SimCoderYoutube avatar Jan 26 '21 18:01 SimCoderYoutube

@SimCoderYoutube thanks for your fast reaction. Your tutorials are awesome! Looking forward to hear from you.

coding-st avatar Jan 26 '21 18:01 coding-st

Has any found a fix to this?

cyber-portfolio avatar Mar 01 '21 09:03 cyber-portfolio

A potential solution is to use this:

const uid = snapshot.docs[0].ref.path.split('/')[1];

and put that line^ and the rest of the code in that function in a try catch block. The line above will throw an error if there is no documents (posts), so for users where this throws an error, just catch, and do nothing since its pointless to get the posts of a user with no posts.

cerovcecblaze avatar May 02 '21 06:05 cerovcecblaze

I think you should console.log(snapshot) for yourself and try to find the segments data based on the console.log, the snapshot data might be different because firebase might update their way to display the snapshot. For my part i was able to retrieve the data from snapshot..query.C.path.segments[1];

minhquan0902 avatar May 13 '21 18:05 minhquan0902

I encountered this error while following the video. What does the EP mean? I had google around for documentation, and could not find any reference to this

MQ-test avatar May 08 '22 16:05 MQ-test