Skip to content

fix(ui-elements): prevent preview cover image tiling and constrain card width - #1481

Open
swarnendusahu10-dotcom wants to merge 1 commit into
RocketChat:developfrom
swarnendusahu10-dotcom:fix/issue-1480-preview-cover-image-tiling
Open

swarnendusahu10-dotcom wants to merge 1 commit into
RocketChat:developfrom
swarnendusahu10-dotcom:fix/issue-1480-preview-cover-image-tiling

Conversation

@swarnendusahu10-dotcom

Copy link
Copy Markdown
Contributor

Summary

Fixes #1480

Problem

When rendering UIKit preview blocks (such as GitHub PR/issue link previews), two layout issues caused the preview image to tile across the viewport:

  1. MessageGenericPreviewCoverImage applied background-image: url(...) without background-repeat: no-repeat, background-size: cover, or background-position: center, causing the image to tile horizontally and vertically whenever the container exceeded the image's intrinsic size (e.g., on wide viewports or when zoomed out).
  2. MessageGenericPreview had no max-width constraint, allowing the preview card to stretch across the full message width and expand the aspect-ratio spacer proportionally.
  3. Unvalidated url interpolation in url(${url}) and unguarded height / width division could cause broken styles on invalid URLs or zero/missing dimensions.

Changes

  • packages/ui-elements/src/components/MessageGenericPreview/MessageGenericPreviewCoverImage.js:
    • Added background-repeat: no-repeat, background-position: center, background-size: cover, width: 100%, and overflow: hidden.
    • Added getSafeImageUrl() to allow only http: / https: URLs and safely escape the URL via JSON.stringify().
    • Guarded aspectRatioPadding against missing, 0, or non-finite width/height values.
  • packages/ui-elements/src/components/MessageGenericPreview/MessageGenericPreview.styles.js:
    • Constrained preview card with width: 100%; max-width: 368px; (matching Rocket.Chat's preview card width and scaling cleanly on mobile viewports).
  • packages/ui-elements/src/components/MessageGenericPreview/MessageGenericPreviewContent.js:
    • Added min-width: 0; flex: 1; overflow-wrap: break-word; on .ec-message-generic-preview__content-wrapper so long titles/URLs wrap cleanly on narrow mobile screens.
  • .changeset/fix-preview-cover-image-tiling.md: Added patch changeset for @embeddedchat/ui-elements.

Verification

  • ESLint on all modified files: 0 errors, 0 warnings.
  • @embeddedchat/ui-elements Rollup build (yarn build): exited cleanly with code 0.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: UIKit PreviewBlock cover image tiles repeatedly and stretches across viewport when zoomed out

1 participant