Skip to content

Responsive image layout 080526#2360

Closed
simo6529 wants to merge 5 commits into
mainfrom
responsive-image-layout-080526
Closed

Responsive image layout 080526#2360
simo6529 wants to merge 5 commits into
mainfrom
responsive-image-layout-080526

Conversation

@simo6529
Copy link
Copy Markdown
Collaborator

@simo6529 simo6529 commented May 8, 2026

Summary by CodeRabbit

  • New Features

    • Responsive image loading and sizing improvements, plus an optional responsive grid layout for multi-image drops.
  • Refactor

    • Reworked image/fallback rendering to simplify fallback behavior and conditional optimization for responsive images.
  • Tests

    • Substantially expanded tests covering image loaders, responsive behavior, grid layouts, fallback flows, and related interactions.

simo6529 added 4 commits May 8, 2026 10:07
Signed-off-by: Simo <simo@6529.io>
Signed-off-by: Simo <simo@6529.io>
Signed-off-by: Simo <simo@6529.io>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

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

Run ID: ab4b309d-9d2a-451b-adea-0a4f86cb264b

📥 Commits

Reviewing files that changed from the base of the PR and between e4bfea7 and aac2e47.

📒 Files selected for processing (2)
  • __tests__/components/waves/drops/WaveDropPartContentMedias.test.tsx
  • components/waves/drops/WaveDropPartContentMedias.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • components/waves/drops/WaveDropPartContentMedias.tsx
  • tests/components/waves/drops/WaveDropPartContentMedias.test.tsx

📝 Walkthrough

Walkthrough

This PR implements responsive image grid layout for drops and waves by adding responsive image scaling helpers, refactoring FallbackImage for loader support, forwarding responsive-image props through the component hierarchy, and enabling a CSS grid for image-only media with expanded tests.

Changes

Responsive Image Grid for Drops/Waves

Layer / File(s) Summary
Image Scaling Helpers
helpers/image.helpers.ts
RESPONSIVE_DROP_IMAGE_SCALES, getResponsiveDropImageScale(width), and responsiveDropImageLoader added; getScaledResolvedImageUri filters existing backend scale segments before re-appending the requested scale.
FallbackImage Refactor
components/common/FallbackImage.tsx
Refactored to delegate rendering to FallbackImageInner, compute src from usedFallback, remove src state mutations, adjust skip-optimization logic, and conditionally pass loader only when not using fallback.
Props Propagation Chain
components/waves/drops/WaveDrop.tsx, WaveDropContent.tsx, WaveDropPart.tsx, WaveDropPartDrop.tsx, WaveDropPartContent.tsx
Introduces and forwards responsiveImageGrid through the wave/drop component chain (computed true for DropLocation.WAVE); adds stable EMPTY_MENTIONED_GROUPS default in WaveDropPartContent.
Media Image Components
components/drops/view/item/content/media/DropListItemContentMedia.tsx, DropListItemContentMediaImage.tsx
Added imageSizes?: string and useResponsiveImageSrcSet?: boolean props; DropListItemContentMediaImage computes fallbackImageOptimizationProps to enable responsiveDropImageLoader when appropriate and passes sizes={imageSizes}.
Responsive Grid Layout
components/waves/drops/WaveDropPartContentMedias.tsx
Adds isImageMedia helper and responsive two-/three-column size constants; introduces useResponsiveImageGrid gating logic to switch to a responsive CSS grid when enabled and all items are images, and passes imageSizes + useResponsiveImageSrcSet to media items when active.
Test Coverage
__tests__/helpers/image.helpers.test.ts, __tests__/components/common/FallbackImage.test.tsx, __tests__/components/DropListItemContentMediaImage.test.tsx, __tests__/components/drops/view/item/content/media/DropListItemContentMedia.test.tsx, __tests__/components/waves/drops/WaveDrop.test.tsx, __tests__/components/waves/drops/WaveDropPartContent.test.tsx, __tests__/components/waves/drops/WaveDropPartContentMedias.test.tsx
Expanded and rewritten tests: loader-aware next/image mock, responsive loader and rerender behavior for FallbackImage, assertions for imageSizes and useResponsiveImageSrcSet forwarding, WaveDrop location-based responsiveImageGrid passing, responsive grid layout scenarios (columns, mixed media, disabled interaction), and helpers tests for responsive scaling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • ragnep
  • analyticsflowee

Poem

🐰 I hopped through scales and loader dreams,
I nudged the grid to split in streams.
From fallback swaps to responsive art,
I stitched the props and played my part.
Hop, click, and render—images gleam!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Responsive image layout 080526' is vague and generic. It uses a date suffix but provides no meaningful description of the actual changeset (which adds responsive image scaling, grid layouts, loader functions, and component prop extensions). Replace with a more descriptive title that captures the main change, such as 'Add responsive image grid layout and loader support' or 'Implement responsive image scaling and grid display'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch responsive-image-layout-080526

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

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e4bfea79cb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread components/waves/drops/WaveDropPartContentMedias.tsx Outdated
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (2)
components/waves/drops/WaveDropPartContentMedias.tsx (1)

66-67: 💤 Low value

Consider adjusting sizes for the 2-image case.

When activePart.media.length === 2, the grid uses md:tw-grid-cols-2 (50% width per image), but RESPONSIVE_IMAGE_GRID_SIZES always uses 33vw on desktop. This may cause the browser to request smaller images than needed for the 2-column layout.

💡 Suggested improvement
+const RESPONSIVE_IMAGE_GRID_SIZES_2_COL = "(max-width: 767px) 100vw, 50vw";
+const RESPONSIVE_IMAGE_GRID_SIZES_3_COL = "(max-width: 767px) 100vw, 33vw";

 // In the component:
+const responsiveImageSizes =
+  activePart.media.length === 2
+    ? RESPONSIVE_IMAGE_GRID_SIZES_2_COL
+    : RESPONSIVE_IMAGE_GRID_SIZES_3_COL;

 // Then use responsiveImageSizes instead of RESPONSIVE_IMAGE_GRID_SIZES

Also applies to: 131-133

🤖 Prompt for 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.

In `@components/waves/drops/WaveDropPartContentMedias.tsx` around lines 66 - 67,
The sizes used for responsive images aren't updated for the 2-image grid: when
activePart.media.length === 2 the component sets desktopGridColumnClassName to
"md:tw-grid-cols-2" but RESPONSIVE_IMAGE_GRID_SIZES (used to set the image sizes
attribute) still returns desktop widths based on a 3-column layout (33vw).
Update the logic in WaveDropPartContentMedias to detect the 2-image case and
return/assign a different sizes string for the md breakpoint (e.g., ~50vw per
image) whenever activePart.media.length === 2; modify both the
desktopGridColumnClassName/RESPONSIVE_IMAGE_GRID_SIZES usage sites (including
the other occurrence around the second image-rendering block) so the <img> sizes
attribute matches the actual md grid columns.
__tests__/components/DropListItemContentMediaImage.test.tsx (1)

15-47: ⚡ Quick win

Cover the sizes forwarding path in the responsive-image test.

Right now this only proves that responsive mode turns on optimize and passes a loader. If DropListItemContentMediaImage stops forwarding the sizes hint, this suite will still pass even though the browser would pick the wrong candidates. Exposing sizes on the FallbackImage mock and asserting it here would close that gap.

🧪 Suggested test tightening
       (
         {
           alt,
           primarySrc,
           fallbackSrc,
           optimize,
           loader,
+          sizes,
           onClick,
           onError,
           onLoad,
         }: any,
         ref: any
       ) => (
         <img
           ref={ref}
           alt={alt}
           src={primarySrc}
           data-fallback-src={fallbackSrc}
           data-optimize={optimize === undefined ? "" : String(optimize)}
           data-has-loader={loader ? "true" : "false"}
+          data-sizes={sizes ?? ""}
           onClick={onClick}
           onError={onError}
           onLoad={onLoad}
         />
       )
@@
   it("uses the responsive loader only when responsive srcset mode is enabled", () => {
     render(
-      <DropListItemContentMediaImage src="img" useResponsiveImageSrcSet />
+      <DropListItemContentMediaImage
+        src="img"
+        useResponsiveImageSrcSet
+        imageSizes="100vw"
+      />
     );

     const img = screen.getByAltText("Drop media");
     expect(img).toHaveAttribute("data-optimize", "true");
     expect(img).toHaveAttribute("data-has-loader", "true");
+    expect(img).toHaveAttribute("data-sizes", "100vw");
   });

Also applies to: 101-109

🤖 Prompt for 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.

In `@__tests__/components/DropListItemContentMediaImage.test.tsx` around lines 15
- 47, The test's FallbackImage mock in DropListItemContentMediaImage.test.tsx
doesn't expose the sizes prop, so add sizes to the mocked component's props
(alongside alt, primarySrc, fallbackSrc, optimize, loader, onClick, onError,
onLoad) and render it as an attribute (e.g., data-sizes={sizes}) in the returned
<img>; then update the responsive-image test to assert that
DropListItemContentMediaImage forwards the expected sizes hint to the
FallbackImage mock (check data-sizes value) to cover the sizes forwarding path
for responsive mode.
🤖 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.

Nitpick comments:
In `@__tests__/components/DropListItemContentMediaImage.test.tsx`:
- Around line 15-47: The test's FallbackImage mock in
DropListItemContentMediaImage.test.tsx doesn't expose the sizes prop, so add
sizes to the mocked component's props (alongside alt, primarySrc, fallbackSrc,
optimize, loader, onClick, onError, onLoad) and render it as an attribute (e.g.,
data-sizes={sizes}) in the returned <img>; then update the responsive-image test
to assert that DropListItemContentMediaImage forwards the expected sizes hint to
the FallbackImage mock (check data-sizes value) to cover the sizes forwarding
path for responsive mode.

In `@components/waves/drops/WaveDropPartContentMedias.tsx`:
- Around line 66-67: The sizes used for responsive images aren't updated for the
2-image grid: when activePart.media.length === 2 the component sets
desktopGridColumnClassName to "md:tw-grid-cols-2" but
RESPONSIVE_IMAGE_GRID_SIZES (used to set the image sizes attribute) still
returns desktop widths based on a 3-column layout (33vw). Update the logic in
WaveDropPartContentMedias to detect the 2-image case and return/assign a
different sizes string for the md breakpoint (e.g., ~50vw per image) whenever
activePart.media.length === 2; modify both the
desktopGridColumnClassName/RESPONSIVE_IMAGE_GRID_SIZES usage sites (including
the other occurrence around the second image-rendering block) so the <img> sizes
attribute matches the actual md grid columns.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 63a884f2-a8f5-4565-ac22-0bd13d95f2a4

📥 Commits

Reviewing files that changed from the base of the PR and between 5dcdc91 and e4bfea7.

📒 Files selected for processing (17)
  • __tests__/components/DropListItemContentMediaImage.test.tsx
  • __tests__/components/common/FallbackImage.test.tsx
  • __tests__/components/drops/view/item/content/media/DropListItemContentMedia.test.tsx
  • __tests__/components/waves/drops/WaveDrop.test.tsx
  • __tests__/components/waves/drops/WaveDropPartContent.test.tsx
  • __tests__/components/waves/drops/WaveDropPartContentMedias.test.tsx
  • __tests__/helpers/image.helpers.test.ts
  • components/common/FallbackImage.tsx
  • components/drops/view/item/content/media/DropListItemContentMedia.tsx
  • components/drops/view/item/content/media/DropListItemContentMediaImage.tsx
  • components/waves/drops/WaveDrop.tsx
  • components/waves/drops/WaveDropContent.tsx
  • components/waves/drops/WaveDropPart.tsx
  • components/waves/drops/WaveDropPartContent.tsx
  • components/waves/drops/WaveDropPartContentMedias.tsx
  • components/waves/drops/WaveDropPartDrop.tsx
  • helpers/image.helpers.ts

Signed-off-by: Simo <simo@6529.io>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 8, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
B Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@simo6529 simo6529 closed this May 11, 2026
@simo6529 simo6529 deleted the responsive-image-layout-080526 branch May 11, 2026 06:37
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.

1 participant