Skip to content

fix(core): show an empty message preview when there is nothing to describe - #3827

Merged
oliverlaz merged 1 commit into
developfrom
fix/message-preview-empty-attachments-develop
Sep 25, 2026
Merged

oliverlaz merged 1 commit into
developfrom
fix/message-preview-empty-attachments-develop

Conversation

@oliverlaz

Copy link
Copy Markdown
Member

🎯 Goal

A message or draft with no text and no attachments rendered a bogus attachment summary as its preview. It showed up in the SampleApp Drafts list as a literal {{count}} Files during the iPhone Duo device pass (RN-429). The same hook also feeds the channel-list last-message preview, the thread list, the reply preview and the SampleApp Reminders list.

The easiest way to hit it: in a channel, long-press a message → Reply, type nothing, and go back. stream-chat saves a draft that has only a quoted_message_id, so the Drafts tab shows {{count}} Files.

Linear: RN-432 · Same fix on V10: #3826

🛠 Implementation details

useMessagePreviewText had no exit for "nothing to describe", so it fell through to its attachment wording:

message.attachments before after
absent literal {{count}} Files: count is undefined, so no _one/_other key matches ''
[] "0 Audios": onlyAudio is 0 === 0 ''

It now returns an empty preview once the text check has passed and there are no attachments. The sibling useMessagePreviewIcon already returns null in that case, and it guards onlyAudio with audios?.length && for exactly this reason.

Deleted messages, polls, locations, giphys and text all return before the new check, so they are unaffected. Mixed attachments still read "N Files".

🎨 UI Changes

The rows that showed {{count}} Files or "0 Audios" now show an empty subtitle, the same as their icon, which was already absent. No other visual change.

🧪 Testing

New package/src/hooks/messagePreview/__tests__/useMessagePreviewText.test.tsx:

  • Regression: an absent attachments and an empty one both return ''. Both failed before the fix.
  • Unchanged behaviour: mixed attachments give "2 Files", audio-only gives "2 Audios", and text wins over attachments. The counted cases use waitFor, because translations load asynchronously in tests.
Gate Result
yarn lint exit 0
cd package && yarn test:typecheck exit 0
yarn build succeeds
yarn test:unit 186 suites, 1511 passed (14 skipped), 12 snapshots

Not checked in the running app. The change is covered by the hook tests.

☑️ Checklist

  • I have signed the Stream CLA (required)
  • PR targets the develop branch
  • Documentation is updated — not needed, no API change
  • New code is tested in main example apps, including all possible scenarios
    • SampleApp iOS and Android
    • Expo iOS and Android

…cribe

A message or draft with no text and no attachments fell through to the
attachment wording in useMessagePreviewText: an absent `attachments`
rendered a literal "{{count}} Files", and an empty array matched
`onlyAudio` (0 === 0) and rendered "0 Audios". Return an empty preview
instead, matching useMessagePreviewIcon, which already returns null in
that case.

Refs RN-432
@Stream-SDK-Bot

Copy link
Copy Markdown
Contributor

SDK Size

title develop branch diff status
js_bundle_size 2032 KB 2032 KB +5 B 🟢

@oliverlaz
oliverlaz merged commit 1abca98 into develop Sep 25, 2026
10 checks passed
@oliverlaz
oliverlaz deleted the fix/message-preview-empty-attachments-develop branch September 25, 2026 13:46
oliverlaz added a commit that referenced this pull request Sep 25, 2026
…cribe (#3826)

## 🎯 Goal

A message or draft with no text and no attachments rendered a bogus
attachment summary as its preview. It showed up in the SampleApp Drafts
list during the iPhone Duo device pass (RN-429), and the same hook also
feeds the channel-list last-message preview, the thread list, the reply
preview and the SampleApp Reminders list.

Linear:
[RN-432](https://linear.app/stream/issue/RN-432/message-preview-shows-0-files-0-audios-for-messages-with-nothing-to)
· Same fix on `develop`: #3827

## 🛠 Implementation details

`useMessagePreviewText` had no exit for "nothing to describe", so it
fell through to its attachment wording:

| `message.attachments` | before | after |
| --- | --- | --- |
| absent | "0 Files" | `''` |
| `[]` | "0 Audios" — `onlyAudio` is `0 === 0` | `''` |

It now returns an empty preview once the text check has passed and there
are no attachments. The sibling `useMessagePreviewIcon` already returns
`null` in that case, and it guards `onlyAudio` with `audios?.length &&`
for exactly this reason. The early return also makes the fall-through's
`count: attachmentsLength ?? 0` workaround unnecessary: that workaround
had only turned develop's literal `{{count}} Files` into "0 Files".

Deleted messages, polls, locations, giphys and text all return before
the new check, so they are unaffected. Mixed attachments still read "N
Files".

## 🎨 UI Changes

The rows that showed "0 Files" or "0 Audios" now show an empty subtitle,
the same as their icon, which was already absent. No other visual
change.

## 🧪 Testing

New
`package/src/hooks/messagePreview/__tests__/useMessagePreviewText.test.tsx`:

- **Regression:** an absent `attachments` and an empty one both return
`''`. Before the fix these two cases failed with exactly `"0 Files"` and
`"0 Audios"`.
- **Unchanged behaviour:** mixed attachments give "2 Files", audio-only
gives "2 Audios", and text wins over attachments.

| Gate | Result |
| --- | --- |
| `yarn lint` | exit 0 |
| `cd package && yarn test:typecheck` | exit 0 |
| `yarn build` | succeeds; `src/i18n/keys.ts` unchanged |
| `yarn test:unit` | 2010 passed, 13 skipped, 1 failed. The failure is
`MessageList pagination › scroll to bottom button`, which the test file
marks as flaky (~20% of runs, pre-existing on V10). It passed 3/3 both
with and without this change. |

Not checked in the running app. The change is covered by the hook tests.

## ☑️ Checklist

- [x] I have signed the [Stream
CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform)
(required)
- [ ] PR targets the `develop` branch — targets `V10`; the `develop` fix
is #3827
- [x] Documentation is updated — not needed, no API change
- [ ] New code is tested in main example apps, including all possible
scenarios
  - [ ] SampleApp iOS and Android
  - [ ] Expo iOS and Android
@github-actions github-actions Bot mentioned this pull request Sep 25, 2026
6 tasks
@stream-ci-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 9.9.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants