Skip to content

[UI] Add fitContainer rendering mode to normalize thumbnails - #7918

Open
hiyach28 wants to merge 2 commits into
layer5io:masterfrom
hiyach28:fix-normalized-thumbnails
Open

[UI] Add fitContainer rendering mode to normalize thumbnails#7918
hiyach28 wants to merge 2 commits into
layer5io:masterfrom
hiyach28:fix-normalized-thumbnails

Conversation

@hiyach28

@hiyach28 hiyach28 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes inconsistent thumbnail rendering on the Resources → Articles grid by introducing an opt-in fitContainer rendering mode.

Previously, article thumbnails containing SVGs and raster images with widely varying intrinsic dimensions rendered at noticeably different visual sizes. This resulted in uneven card layouts, inconsistent spacing, and poor visual balance across the grid.

Instead of normalizing individual assets or introducing page-specific rendering logic, this PR adds a reusable rendering abstraction that allows thumbnails to scale consistently while preserving their original aspect ratios and existing rendering behavior elsewhere in the application.

Fixes #7912


Root Cause

The issue was caused by the clashes between image dimensions and the existing rendering abstraction.

During investigation, several observations emerged:

  • SVG and raster images follow different rendering paths inside src/components/image.js.
  • Large SVGs naturally scaled down correctly because they exceeded the available drawing area.
  • Smaller SVGs (such as the Istio thumbnail) remained constrained to their intrinsic dimensions.
  • Because those images never expanded to fill the available canvas, object-fit: contain could not normalize their rendering, resulting in inconsistent visual sizing across the grid.

This meant thumbnails with different intrinsic dimensions produced inconsistent visual output even though they shared the same card layout.


Investigation

Several implementation strategies were explored before arriving at the final solution.

  1. Using object-fit: cover : Although this aligned thumbnail sizes, it cropped wide and tall logos, resulting in loss of important visual content.
  2. Wrapper alignment and padding adjustments: Adjusting Flexbox alignment and wrapper padding improved some cases but treated only the symptoms. Different aspect ratios still produced inconsistent visual weight.
  3. Bounding-box based CSS normalization: Constraining thumbnails inside a fixed square produced new inconsistencies:
    • wide logos appeared too small
    • tall logos appeared oversized
    • diagrams became difficult to read
  4. Normalizing individual assets: Updating individual SVGs would only solve the currently affected assets while leaving the rendering abstraction unchanged. Every future upload would require manual tuning.

Final Solution

Instead of modifying assets or introducing page-specific rendering logic, this PR normalizes rendering at the abstraction responsible for image presentation.
This addresses the underlying rendering behavior rather than individual assets.

  ResourcesGrid
        │
        │ declares layout intent
        ▼
      Card
        │
        │ establishes thumbnail canvas
        ▼
      Image
        │
        │ normalizes SVG and raster rendering

ResourcesGrid: Declares layout intent by enabling fitContainer only for article thumbnails. It's unaware of rendering implementation details.

Card: Owns layout. It establishes the drawing canvas and spacing while forwarding rendering intent. It does not contain image-specific logic.

Image: Owns image rendering. The new fitContainer mode normalizes rendering for both SVG and raster images while preserving aspect ratio and respecting the existing rendering pipeline. By placing the abstraction here, rendering behavior remains centralized and reusable.


Why this approach

This solution addresses the problem at the rendering abstraction rather than introducing page-specific or asset-specific fixes.

The new fitContainer mode is opt-in, allowing the Resources → Articles grid to normalize thumbnail rendering without affecting existing consumers. By centralizing the behavior in Image, the implementation works consistently for both SVG and raster images while preserving aspect ratios and avoiding asset modifications.

This approach provides several benefits:

  • Introduces a reusable rendering abstraction instead of a one-off fix.
  • Preserves existing rendering behavior for all current consumers unless fitContainer is explicitly enabled.
  • Eliminates the need for asset-specific adjustments or special-case rendering logic.
  • Maintains clear separation of responsibilities between ResourcesGrid, Card, and Image.
  • Enables future sections to adopt consistent thumbnail rendering with a single opt-in prop, without duplicating implementation.

Screenshots

Before
image

After

image

Testing

Verified locally using the Gatsby development server.

Verified

  • Resources → Articles grid
  • SVG thumbnails
  • Raster thumbnails
  • Wide logos
  • Tall logos
  • Square logos
  • Light theme
  • Dark theme
  • Aspect ratio preserved
  • No clipping
  • Consistent spacing
  • Consistent alignment

The implementation was validated against thumbnails with significantly different intrinsic dimensions, including Kubernetes, Consul, GitHub, Docker, and Istio.


Checklist

  • Verified locally
  • No regressions to existing consumers
  • Aspect ratios preserved
  • Signed commits

I signed my commits.

Summary by CodeRabbit

  • New Features

    • Added improved image fitting for resource cards, allowing images to display fully within their containers.
    • Article cards now support contained, non-cropped images with consistent sizing across image formats.
    • Responsive images and SVGs now adapt more reliably to their available space.
  • Bug Fixes

    • Improved thumbnail alignment, spacing, and sizing in non-list card views.
    • Updated medium-width layouts to provide more consistent thumbnail heights and presentation.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3c92e5c9-e159-4fd9-8a38-3177eb829ac9

📥 Commits

Reviewing files that changed from the base of the PR and between cad2f1d and 358b610.

📒 Files selected for processing (1)
  • src/components/image.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/image.js

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The PR adds optional fitContainer support to Card and Image. ResourceGrid enables it for article cards. Fitted thumbnails use full dimensions, centered alignment, padding, and object-fit: contain.

Changes

Article card image fitting

Layer / File(s) Summary
Card and Image fit-container behavior
src/components/Card/..., src/components/image.js
Card forwards fitContainer to its wrapper and Image. When enabled, fitted images use full dimensions, centered layout, padding, and object-fit: contain for SVG and GatsbyImage rendering.
Resource grid article-card wiring
src/sections/Resources/Resources-grid/index.js
ResourceGrid passes fitContainer={frontmatter.type === "Article"} to each card.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 358b6

This PR adds an opt-in thumbnail rendering mode for the Articles grid while preserving existing behavior elsewhere; no actionable merge-blocking risk remains beyond normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant ResourceGrid
  participant Card
  participant Image
  ResourceGrid->>Card: pass fitContainer for Article cards
  Card->>Image: pass fitContainer
  Image->>Image: compute contain and full-size styles
  Image-->>Card: render fitted image
Loading
🚥 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 clearly describes the main UI change: adding a fitContainer rendering mode to normalize thumbnails.
Linked Issues check ✅ Passed The changes satisfy issue #7912. ResourceGrid enables fitContainer for Article cards, and the shared Card and Image components normalize thumbnail sizing and alignment while preserving existing behavi…
Out of Scope Changes check ✅ Passed All changes support the linked issue and PR objective. The implementation is limited to shared thumbnail rendering and enabling that behavior for article cards in ResourceGrid.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Full details: Linked Issues check

Explanation

The changes satisfy issue #7912. ResourceGrid enables fitContainer for Article cards, and the shared Card and Image components normalize thumbnail sizing and alignment while preserving existing behavior for other consumers.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1 files.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/components/image.js

Parsing error: [BABEL] /src/components/image.js: babel-preset-gatsby has been loaded, which consumes config generated by the Gatsby CLI. Set NODE_ENV=test to bypass, or run gatsby build first. (While processing: "/node_modules/babel-preset-gatsby/index.js")


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/Card/Card.style.js`:
- Around line 74-83: Update the styled component’s `$fitContainer` styling in
the relevant card wrapper so it retains a definite height at the 992–1200px
breakpoint, overriding the later `.post-thumb-block` auto-height rule. Preserve
the existing responsive media-query behavior and ensure fitted thumbnails
continue resolving their 100% height consistently across article aspect ratios.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1d1d7f03-278c-4313-bfa6-e5f970472143

📥 Commits

Reviewing files that changed from the base of the PR and between 7359a55 and 6110239.

📒 Files selected for processing (4)
  • src/components/Card/Card.style.js
  • src/components/Card/index.js
  • src/components/image.js
  • src/sections/Resources/Resources-grid/index.js

Comment thread src/components/Card/Card.style.js
Signed-off-by: hiyach28 <hiyach28@gmail.com>
@hiyach28
hiyach28 force-pushed the fix-normalized-thumbnails branch from 6110239 to cad2f1d Compare August 4, 2026 06:09
@saurabhraghuvanshii

Copy link
Copy Markdown
Member

@hiyach28 Did you checked other pages like blogs? if there card got misaligned.

@hiyach28

hiyach28 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@saurabhraghuvanshii I have only worked on the Articles page as explicitly mentioned in the issue.
However did notice an alignment issue in other pages as well
image
If this approach looks good to go, I can implement them to other pages and push a commit here itself, or open a new issue/pr for overall change in the resource page. Please let me know what works

@saurabhraghuvanshii

Copy link
Copy Markdown
Member

@hiyach28 Please imporve all pages and take care for this page also /blog

@hiyach28

hiyach28 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

I have drafted an implementation plan for the same, so it's easier to review:

Objective

Extend the existing fitContainer rendering mode to all applicable resource pages that use the shared Card component, ensuring consistent thumbnail rendering while keeping the implementation centralized.

Scope

Enable fitContainer on pages using the shared Card component:

  • Articles
  • Blog
  • Resources
  • News
  • Events

Implementation

  1. Verify each resource page uses the shared Card component.
  2. Enable the existing fitContainer capability by passing:
    fitContainer={true}
    wherever the shared Card is rendered.
  3. Avoid introducing duplicate rendering logic or modifying the shared implementation unless a regression is discovered.

Files Expected to Change

  • Resource page grid/list components that render the shared Card

No additional changes are expected in the shared implementation (Card, Card.style, image.js) unless issues are found during validation.

Success Criteria

  • fitContainer enabled across all applicable resource pages.
  • Thumbnail rendering is consistent.
  • No layout or theme regressions.
  • Shared Card remains the single source of truth.

@rishiraj38 rishiraj38 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Conflicts!!!

Signed-off-by: hiyach28 <hiyach28@gmail.com>
@hiyach28
hiyach28 force-pushed the fix-normalized-thumbnails branch from 03b8d26 to 358b610 Compare August 24, 2026 23:53
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Preview deployment: https://layer5.io/pr-preview/pr-7918/

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.

[UI] Fix image alignment in article cards

3 participants