Fix/interactive message stale image cache key#9903
Conversation
The attachment image components froze their expo-image cacheKey (fileId) to the first imageUrl via useRef. On an in-place post edit (same post id, e.g. interactive-message button updates) the new image URL was rendered under the old cacheKey, so expo-image kept serving the originally cached image and never refreshed. Derive the cacheKey from the current imageUrl with useMemo so it updates when the URL changes. Affects both render paths: message_attachments/attachment_image and block_renderer/mm_blocks_image. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Asserts the expo-image cache id (fileId) tracks imageUrl across re-renders, so an in-place post edit to a new image URL is not served from the stale cache. Fails on the previous useRef implementation. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Hello @cevn, Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here. Per the Mattermost Contribution Guide, we need to add you to the list of approved contributors for the Mattermost project. Please help complete the Mattermost contribution license agreement? This is a standard procedure for many open source projects. Please let us know if you have any questions. We are very happy to have you join our growing community! If you're not yet a member, please consider joining our Contributors community channel to meet other contributors and discuss new opportunities with the core team. |
📝 WalkthroughWalkthroughTwo components switch fileId derivation from mutable refs to memoized values from imageUrl, and use that value consistently for gallery payloads and image identifiers. AttachmentImage also gains tests for cache ID updates, gallery opening, and invalid URL handling. ChangesfileId memoization and gallery caching
Sequence Diagram(s)Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@app/components/post_list/post/body/content/message_attachments/attachment_image/index.test.tsx`:
- Around line 113-124: The test in attachment_image/index.test.tsx only verifies
that the expected gallery item is present via openGalleryAtIndex and
expect.arrayContaining, so extra duplicate items could slip through. Update the
assertion around openGalleryAtIndex to also check the gallery items array length
is exactly 1 while keeping the existing item shape checks for the
IMAGE_URL-derived entry.
- Around line 78-130: The test descriptions in AttachmentImage’s spec do not
follow the required it('should...') convention. Update the four test names in
the AttachmentImage test block to start with “should” while keeping the existing
assertions and behavior unchanged, and make sure the renamed cases still clearly
describe ProgressiveImage rendering, cache id updates on rerender, gallery
opening, and invalid URL handling.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e6888956-9758-4181-8c9b-a2f31d56307f
📒 Files selected for processing (3)
app/components/block_renderer/mm_blocks_image.tsxapp/components/post_list/post/body/content/message_attachments/attachment_image/index.test.tsxapp/components/post_list/post/body/content/message_attachments/attachment_image/index.tsx
- Rename the four AttachmentImage tests to the repo's it('should...') convention
- Assert the gallery items array length is exactly 1 (not just contains)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
/check-cla |
|
@saturninoabril or @amyblais can you take a look and lmk if anything needs to be done to merge this? It fixes a real bug for us on the mobile app regarding edited integration posts with image attachments. |
I'll add some reviewers to the PR. |
Summary
We have a Mattermost plugin integration which utilizes Mattermost’s “interactive messages” feature. The plugin updates the attachments on a message in-place, specifically the “image_url” attachment, whenever a user clicks an interactive action button on the same message. This image URL refresh had previously been working as expected across all Mattermost platforms (Desktop, Web, and Mobile).
Beginning some time in late 2025 however, the updated image has failed to properly render on Mattermost Mobile, for all posts. Users are currently required to refresh the channel (or simply visit another channel and return to the original channel) to see the updated image.
The image update continues to work as expected on all non-mobile Mattermost platforms, i.e. Desktop and Web versions. We believe that the regression may have been introduced with Mattermost Mobile v2.33.0.
Upon deeper analysis of the Mattermost open-source code, we believe the issue is related to a stale attachment image URL essentially being cached and reused by the client at rendering time. A callback to refresh the Mattermost message continues to use this stale URL value, instead of the updated value provided to the callback.
This pull request makes a change to derive the cache key from the current image URL, whilst utilizing the
useMemomethod, so that the URL is properly updated upon being changed.We have tested and verified this change on our own iOS development version of Mattermost Mobile, released via Test Flight.
Affects both render paths: message_attachments/attachment_image and
block_renderer/mm_blocks_image.
Ticket Link
Checklist
E2E/Run(orE2E/Run-iOS/E2E/Run-Androidfor platform-specific runs).Device Information
This PR was tested on:
Screenshots
Release Note