Skip to content

fix: preserve aspect ratio for Giphy and Tenor attachments#40311

Open
Pragatigupta2508 wants to merge 2 commits intoRocketChat:developfrom
Pragatigupta2508:fix-image-aspect-ratio-v2
Open

fix: preserve aspect ratio for Giphy and Tenor attachments#40311
Pragatigupta2508 wants to merge 2 commits intoRocketChat:developfrom
Pragatigupta2508:fix-image-aspect-ratio-v2

Conversation

@Pragatigupta2508
Copy link
Copy Markdown

@Pragatigupta2508 Pragatigupta2508 commented Apr 25, 2026

🐛 Issue

External images from Giphy and Tenor were being forced into a square aspect ratio, causing distortion.

🔍 Root Cause

The img element in AttachmentImage used fixed width and height, overriding intrinsic dimensions.

✅ Fix

Removed fixed width/height and applied responsive styling:

  • max-width: 100%
  • height: auto
  • object-fit: contain

💡 Result

  • Giphy and Tenor images now preserve original aspect ratio
  • No impact on regular uploaded images

Summary by CodeRabbit

  • Bug Fixes
    • Improved image rendering in message attachments: images now size responsively to their container (use intrinsic sizing with max bounds), maintain aspect ratio, and fit cleanly within available space while preserving lazy loading and existing metadata attributes.

@Pragatigupta2508 Pragatigupta2508 requested a review from a team as a code owner April 25, 2026 14:46
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Apr 25, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 25, 2026

⚠️ No Changeset found

Latest commit: 673ae1e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2d9da4f2-ebb9-4af1-a671-530ffc3ae2c7

📥 Commits

Reviewing files that changed from the base of the PR and between b50d6af and 673ae1e.

📒 Files selected for processing (1)
  • apps/meteor/client/components/message/content/attachments/structure/AttachmentImage.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/client/components/message/content/attachments/structure/AttachmentImage.tsx

Walkthrough

The image component's dimension handling changes from explicit width/height attributes to responsive inline styles that cap rendered size with maxWidth: 100% / maxHeight: 100%, let intrinsic sizing via width: auto / height: auto, and use objectFit: 'contain'.

Changes

Cohort / File(s) Summary
Image Styling
apps/meteor/client/components/message/content/attachments/structure/AttachmentImage.tsx
Replaced explicit width/height attributes on the <img> with inline responsive styling: maxWidth: 100%, maxHeight: 100%, width: auto, height: auto, and objectFit: 'contain'. Preserved existing data attributes and loading="lazy".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: preserve aspect ratio for Giphy and Tenor attachments' directly aligns with the main change: applying responsive styling to preserve the original aspect ratio of external images from Giphy and Tenor instead of forcing them into a square. The title is concise, specific, and accurately summarizes the primary fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@apps/meteor/client/components/message/content/attachments/structure/AttachmentImage.tsx`:
- Around line 87-91: The image can overflow its aspect-ratio container because
only width is constrained; update the inline style in AttachmentImage (the
element with style { maxWidth:'100%', height:'auto', objectFit:'contain' }) to
constrain height as well so object-fit: 'contain' takes effect — e.g., replace
height:'auto' with height:'100%' (or add maxHeight:'100%') so portrait images
cannot spill out of the parent ImageBox/aspect-ratio wrapper; ensure the change
is applied where the image element is rendered in AttachmentImage.tsx.
🪄 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: 9c95aacf-a0f3-45e6-9f9a-a2000224ad6f

📥 Commits

Reviewing files that changed from the base of the PR and between ceefff9 and b50d6af.

📒 Files selected for processing (1)
  • apps/meteor/client/components/message/content/attachments/structure/AttachmentImage.tsx
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/components/message/content/attachments/structure/AttachmentImage.tsx
🧠 Learnings (4)
📓 Common learnings
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:18.785Z
Learning: In Rocket.Chat PR reviews, maintain strict scope boundaries—when a PR is focused on a specific endpoint (e.g., rooms.favorite), avoid reviewing or suggesting changes to other endpoints that were incidentally refactored (e.g., rooms.invite) unless explicitly requested by maintainers.
📚 Learning: 2026-04-10T22:42:05.539Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 40075
File: apps/meteor/client/views/room/modals/FileUploadModal/FileUploadModal.tsx:69-71
Timestamp: 2026-04-10T22:42:05.539Z
Learning: In `apps/meteor/client/views/room/modals/FileUploadModal/FileUploadModal.tsx`, the submit handler converts an empty/whitespace-only description to `undefined` (`description?.trim() || undefined`) intentionally. All downstream image-rendering components (`AttachmentImage`, `ImagePreview`, `ImageItem`, `ImageGallery`) default `undefined` alt to `''`, so the `<img alt="">` attribute is always present. Do not flag this `undefined` conversion as a bug preventing alt text from being cleared.

Applied to files:

  • apps/meteor/client/components/message/content/attachments/structure/AttachmentImage.tsx
📚 Learning: 2026-04-17T23:32:07.223Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 38357
File: apps/meteor/app/apps/server/converters/messages.ts:348-352
Timestamp: 2026-04-17T23:32:07.223Z
Learning: In `apps/meteor/app/apps/server/converters/messages.ts`, the `timestamp` handler inside `_convertAttachmentsToApp` uses a non-null assertion (`attachment.ts!`) intentionally. The `ts` property on `MessageAttachment` is optional only to accommodate MessageAttachment creation-time scenarios; by the time `_convertAttachmentsToApp` is called, the message has already been stored and the attachment is guaranteed to have a `ts` value. Do not flag this non-null assertion as unsafe during code review.

Applied to files:

  • apps/meteor/client/components/message/content/attachments/structure/AttachmentImage.tsx
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.

Applied to files:

  • apps/meteor/client/components/message/content/attachments/structure/AttachmentImage.tsx
🔇 Additional comments (1)
apps/meteor/client/components/message/content/attachments/structure/AttachmentImage.tsx (1)

82-93: ⚠️ Potential issue | 🟡 Minor

Inconsistent indentation on <img> attributes — uses spaces instead of tabs.

The <img> opening tag uses tabs (consistent with surrounding JSX), but all its attributes use 2 spaces. Re-indent the attributes with tabs to match the file's indentation style.

⛔ Skipped due to learnings
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 40075
File: apps/meteor/client/views/room/modals/FileUploadModal/FileUploadModal.tsx:69-71
Timestamp: 2026-04-10T22:42:05.539Z
Learning: In `apps/meteor/client/views/room/modals/FileUploadModal/FileUploadModal.tsx`, the submit handler converts an empty/whitespace-only description to `undefined` (`description?.trim() || undefined`) intentionally. All downstream image-rendering components (`AttachmentImage`, `ImagePreview`, `ImageItem`, `ImageGallery`) default `undefined` alt to `''`, so the `<img alt="">` attribute is always present. Do not flag this `undefined` conversion as a bug preventing alt text from being cleared.

@Pragatigupta2508
Copy link
Copy Markdown
Author

Thanks for the suggestion! Updated the styling to also constrain height and prevent overflow for portrait images.

@coderabbitai coderabbitai Bot removed the type: bug label Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant