Skip to content
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

Crash - ERROR [TypeError: imageProp.includes is not a function (it is undefined)] #2816

Open
Saad-Bashar opened this issue Nov 27, 2024 · 5 comments

Comments

@Saad-Bashar
Copy link

Saad-Bashar commented Nov 27, 2024

Whenever I get a new message from another user the <Channel /> component crashes. It crashes on the Avatar component from stream chat RN components. The is where it exactly crashes getResizedImageUrl,

uri:
    !imageProp ||
    imageProp.includes(randomImageBaseUrl) ||
    imageProp.includes(randomSvgBaseUrl)
      ? imageProp?.includes(streamCDN)
        ? imageProp
        : `${randomImageBaseUrl}${
            name ? `?name=${getInitials(name)}&size=${size}` : ''
          }`
      : getResizedImageUrl({
          height: size,
          url: imageProp, //  ---------- IT CRASHES ON THIS LINE, imageProp.includes is not a function  ---------
          width: size,
        }),

Please note that all my users are not connected with avatar. Some users may have avatar, some users don't have any avatar. How can we fix this issue? Thanks!

@fathulfahmy
Copy link

fathulfahmy commented Dec 29, 2024

I am getting the same error. The app crashes upon receiving new message on channel screen.

  • Expo: version: 52.0.43

  • Stream Chat: stream-chat-expo: 6.0.1

  • Platform: iOS and Android

  • Full implementation can be viewed here: Link to GitHub blob

  • Screenshot:

  • image

@khushal87
Copy link
Member

Hey @Saad-Bashar @fathulfahmy, I am not able to reproduce this crash but I get this could happen. But to appropriately fix it. I would need to provide the same env. Can you share with me if the user with the image(for which it crashes) has name, and is its imageUrl undefined/null?

@fathulfahmy
Copy link

Thank you @khushal87 for pointing out the cause of error. I mistakenly set user image to an object instead of uri. The issue has been solved for me.

User JSON
"user": {
      "id": "1",
      "name": "Demo User 1",
      "email": "[email protected]",
      "email_verified_at": "2024-12-30T16:40:24.000000Z",
      "created_at": "2024-12-30T16:40:24.000000Z",
      "updated_at": "2024-12-30T16:40:24.000000Z",
      "deleted_at": null,
      "avatar": {
        "uri": "http://172.20.10.3:8000/storage/images/placeholder_image_500_500.png",
        "name": "placeholder_image_500_500.png",
        "type": "image/png"
      },
      "media": []
    }
Incorrect user initialization
      await client.connectUser(
        {
          id: data.user.id,
          name: data.user.name,
          image: data.user.avatar,
        },
        data.chat_token,
      );
Correct user initialization
      await client.connectUser(
        {
          id: data.user.id,
          name: data.user.name,
          image: data.user.avatar.uri,
        },
        data.chat_token,
      );

@khushal87
Copy link
Member

That's the only case in which I can predict something like this will happen. 😅

@khushal87
Copy link
Member

What about you @Saad-Bashar?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants