Skip to content

perf(media): update image handling and dependencies - #682

Open
vivek-gite wants to merge 2 commits into
Project-HAMi:masterfrom
vivek-gite:perf/issue-662-responsive-images
Open

perf(media): update image handling and dependencies#682
vivek-gite wants to merge 2 commits into
Project-HAMi:masterfrom
vivek-gite:perf/issue-662-responsive-images

Conversation

@vivek-gite

@vivek-gite vivek-gite commented Jul 29, 2026

Copy link
Copy Markdown

What type of PR is this?

feature

What this PR does / why we need it:

Implements the responsive-image work from #662 so visitors download image candidates appropriate to the rendered size instead of always receiving large source files.

  • Adds a shared ResponsiveImage component that renders picture, srcSet, sizes, intrinsic dimensions, lazy loading, and async decoding.
  • Generates responsive WebP and original-format variants for the SZZT adopter logo and KubeCon booth banner.
  • Updates the logo wall and relevant image rendering paths while preserving lightbox behavior, alt text, and figure numbering.
  • Adds build-time image-size validation. The full repository scan runs in CI rather than delaying npm start.

This reduces image transfer and decode work on mobile while reserving image space to avoid layout shift.

Which issue(s) this PR fixes:

Fixes #662

AI assistance:

I used AI assistance to help me explore the codebase and review code. But solution was fully authored, manually reviewed, tested by me and take responsibility for all changes in this PR.

Checklist:

  • npm run lint and npm run format:check pass
  • npm run build succeeds for both en and zh
  • Chinese translation updated if English docs changed (or noted why not)
  • Commits are signed off (git commit -s)

Summary by CodeRabbit

  • New Features
    • Added responsive image delivery with optimized WebP and size-specific variants.
    • Updated supported blog and logo images to adapt to screen size and improve loading performance.
    • Preserved access to full-resolution images through the lightbox viewer.
  • Bug Fixes
    • Improved figure captions for images rendered with responsive picture elements.
    • Corrected image sizing within support sections.
  • Chores
    • Added automated image-size validation during documentation builds to help prevent oversized assets.

@hami-robot

hami-robot Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: vivek-gite
Once this PR has been reviewed and has the lgtm label, please assign archlitchi for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@netlify

netlify Bot commented Jul 29, 2026

Copy link
Copy Markdown

Deploy Preview for project-hami ready!

Name Link
🔨 Latest commit b5f6948
🔍 Latest deploy log https://app.netlify.com/projects/project-hami/deploys/6a6b4024ef65c60008264991
😎 Deploy Preview https://deploy-preview-682--project-hami.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@hami-robot

hami-robot Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Welcome @vivek-gite! It looks like this is your first PR to Project-HAMi/website 🎉

@hami-robot hami-robot Bot added the size/XL label Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b10b3ed0-99f4-4d7e-8482-b60c008d0d21

📥 Commits

Reviewing files that changed from the base of the PR and between 7eb9a23 and b5f6948.

📒 Files selected for processing (2)
  • .github/workflows/docs-health.yml
  • package.json

📝 Walkthrough

Walkthrough

Adds a build-time responsive image pipeline with Sharp, size validation, responsive rendering, updated logo and blog content integration, and compatibility changes for figures and lightbox behavior.

Changes

Responsive image delivery

Layer / File(s) Summary
Asset configuration and variant generation
src/data/responsive-images.json, scripts/generate-responsive-images.js, .gitignore
Configured images are validated and converted into WebP and original-format width variants under static/img/responsive.
Image checks and lifecycle wiring
scripts/check-image-sizes.js, scripts/image-size-allowlist.json, package.json, .github/workflows/docs-health.yml
Raster assets are checked against size and dimension limits, allowlisted exceptions are tracked, and image preparation and validation run during start, build, and CI workflows.
Responsive component and content integration
src/components/ResponsiveImage.js, src/components/logoWall.js, blog/..., i18n/zh/..., src/css/custom.css
ResponsiveImage renders configured images with picture sources, and logo and blog content adopt the component with responsive sizing.
Figure and lightbox compatibility
src/client/imageFigureNumber.js, src/theme/utils/useImageLightbox.js
Figure wrapping preserves picture elements, while lightbox previews prefer the original-image override.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SiteContent
  participant ResponsiveImage
  participant Browser
  participant Lightbox
  SiteContent->>ResponsiveImage: pass image source and sizes
  ResponsiveImage->>Browser: render picture with responsive sources
  Browser->>Lightbox: open clicked image
  Lightbox->>Browser: load original lightbox source
Loading

Possibly related PRs

Suggested labels: enhancement

Suggested reviewers: mesutoezdil, rootsongjc, spencercjh

Poem

I’m a rabbit with pixels to spare,
Shrinking big pictures with care.
WebP hops in sight,
Lightboxes shine bright,
Small screens get images just right.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the main media/image-handling and dependency changes.
Linked Issues check ✅ Passed The PR implements responsive image variants, a shared component, lightbox preservation, and build-time image checks required by #662.
Out of Scope Changes check ✅ Passed All changed files support responsive image generation, rendering, validation, or related docs/config; no unrelated edits stand out.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

🧹 Nitpick comments (1)
package.json (1)

16-25: 🚀 Performance & Scalability | 🔵 Trivial

Full regenerate-on-every-run cost will grow with the image set.

images:generate wipes and rebuilds the entire static/img/responsive directory on every prestart/prebuild (per scripts/generate-responsive-images.js line 74), regardless of whether source assets changed. Fine for the current 2-image scope; worth revisiting with content-hash-based incremental generation once more images are migrated to the responsive pipeline, to keep local dev/build startup fast.

🤖 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 `@package.json` around lines 16 - 25, Update the image preparation flow around
images:generate and generate-responsive-images.js so repeated prestart/prebuild
runs skip regeneration when source assets are unchanged. Add content-hash-based
change detection while preserving full generation when inputs change, and ensure
the existing images:check and responsive output behavior remains intact.
🤖 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 `@blog/hami-at-kubecon-eu-2026/index.md`:
- Line 33: Rename the English blog post directory to the required
YYYY-MM-DD-title format, and rename or update its localized counterpart to use
the matching dated title structure. Preserve the post content and ensure all
references to the old directory remain aligned with the new paths.

---

Nitpick comments:
In `@package.json`:
- Around line 16-25: Update the image preparation flow around images:generate
and generate-responsive-images.js so repeated prestart/prebuild runs skip
regeneration when source assets are unchanged. Add content-hash-based change
detection while preserving full generation when inputs change, and ensure the
existing images:check and responsive output behavior remains intact.
🪄 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 Plus

Run ID: f1a7c5ff-d367-46b3-bb6c-cfb524591adb

📥 Commits

Reviewing files that changed from the base of the PR and between 65354a0 and b59d2f3.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (13)
  • .gitignore
  • blog/hami-at-kubecon-eu-2026/index.md
  • i18n/zh/docusaurus-plugin-content-blog/hami-at-kubecon-eu-2026/index.md
  • package.json
  • scripts/check-image-sizes.js
  • scripts/generate-responsive-images.js
  • scripts/image-size-allowlist.json
  • src/client/imageFigureNumber.js
  • src/components/ResponsiveImage.js
  • src/components/logoWall.js
  • src/css/custom.css
  • src/data/responsive-images.json
  • src/theme/utils/useImageLightbox.js

Comment thread blog/hami-at-kubecon-eu-2026/index.md
- Added new scripts for image size checking and generation in package.json.
- Introduced the 'sharp' library for image processing.
- Updated .gitignore to exclude responsive image directory.
- Modified blog and i18n markdown files to use ResponsiveImage component for better image handling.
- Enhanced logoWall component to utilize ResponsiveImage for logos.
- Adjusted CSS for support wrapper to ensure proper image display.
- Fixed image lightbox functionality to support data attributes for image sources.

These changes improve image management and enhance the overall performance of the application.

Signed-off-by: Gite Vivek Kumar <vivekkumargite@outlook.com>
@vivek-gite
vivek-gite force-pushed the perf/issue-662-responsive-images branch from b59d2f3 to 7eb9a23 Compare July 29, 2026 18:52

@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 `@scripts/check-image-sizes.js`:
- Line 11: Update the supportedExtensions set in check-image-sizes.js to include
the .avif and .gif extensions, ensuring those raster formats are included in the
existing image size validation.
🪄 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 Plus

Run ID: 9e4862d5-69f0-4c12-8fe7-bd85c41e6c39

📥 Commits

Reviewing files that changed from the base of the PR and between b59d2f3 and 7eb9a23.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (13)
  • .gitignore
  • blog/hami-at-kubecon-eu-2026/index.md
  • i18n/zh/docusaurus-plugin-content-blog/hami-at-kubecon-eu-2026/index.md
  • package.json
  • scripts/check-image-sizes.js
  • scripts/generate-responsive-images.js
  • scripts/image-size-allowlist.json
  • src/client/imageFigureNumber.js
  • src/components/ResponsiveImage.js
  • src/components/logoWall.js
  • src/css/custom.css
  • src/data/responsive-images.json
  • src/theme/utils/useImageLightbox.js
🚧 Files skipped from review as they are similar to previous changes (11)
  • src/client/imageFigureNumber.js
  • scripts/image-size-allowlist.json
  • blog/hami-at-kubecon-eu-2026/index.md
  • src/components/logoWall.js
  • package.json
  • src/components/ResponsiveImage.js
  • src/data/responsive-images.json
  • src/css/custom.css
  • i18n/zh/docusaurus-plugin-content-blog/hami-at-kubecon-eu-2026/index.md
  • src/theme/utils/useImageLightbox.js
  • scripts/generate-responsive-images.js

const rootDirectory = path.resolve(__dirname, "..");
const staticDirectory = path.join(rootDirectory, "static");
const responsiveDirectory = path.join(staticDirectory, "img", "responsive");
const supportedExtensions = new Set([".jpeg", ".jpg", ".png", ".webp"]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Include AVIF and GIF in the raster size check.

These raster formats currently bypass validation, so oversized assets can be added under static/ without an exemption.

Proposed fix
-const supportedExtensions = new Set([".jpeg", ".jpg", ".png", ".webp"]);
+const supportedExtensions = new Set([
+  ".avif",
+  ".gif",
+  ".jpeg",
+  ".jpg",
+  ".png",
+  ".webp",
+]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const supportedExtensions = new Set([".jpeg", ".jpg", ".png", ".webp"]);
const supportedExtensions = new Set([
".avif",
".gif",
".jpeg",
".jpg",
".png",
".webp",
]);
🤖 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 `@scripts/check-image-sizes.js` at line 11, Update the supportedExtensions set
in check-image-sizes.js to include the .avif and .gif extensions, ensuring those
raster formats are included in the existing image size validation.

@mesutoezdil mesutoezdil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

checked the deploy preview, the variants resolve and the srcset looks right, few notes below.

title says chore: but this is a perf change, pls retitle to match the issue (perf(media): ...).

the pr description doesn't follow the repo template, pls fill the 'what this PR does / why we need it' section.

no ai assistance disclosure is present. if any ai tool was used, it must be disclosed per CONTRIBUTING.md: https://github.com/Project-HAMi/HAMi/blob/master/CONTRIBUTING.md#ai-assistance-notice

}

async function main() {
const images = await findRasterImages(staticDirectory);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this walks all 194 rasters in static/ on every prestart, pls keep it in ci only so npm start doesn't wait on it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated images:prepare so local start/build hooks only generate responsive variants. The full raster-size scan now runs as an explicit Docs Health CI step; it remains available locally via npm run images:check.

}),
);

if (violations.length > 0 || staleExemptions.size > 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

a stale exemption shouldn't fail the build, deleting or shrinking an allowlisted img would break everyone's npm start.

const sourcePath = path.join(staticDirectory, src.replace(/^\//, ""));
const metadata = await sharp(sourcePath).metadata();

if (metadata.width !== config.width || metadata.height !== config.height) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this breaks the build if anyone re-exports the src img, pls read the dims from the file instead of asserting them.

import useBaseUrl from "@docusaurus/useBaseUrl";
import responsiveImages from "../data/responsive-images.json";

function getVariantPath(src, width, extension) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same getVariantPath is copied in scripts/generate-responsive-images.js, if either drifts the srcset 404s silently, pls share one helper.

"static/img/adopters/ecloud.jpg": "Existing adopter logo; migrate through the responsive pipeline before changing it.",
"static/img/adopters/linkedin.png": "Existing adopter logo; migrate through the responsive pipeline before changing it.",
"static/img/adopters/pingan-securities.png": "Existing adopter logo; migrate through the responsive pipeline before changing it.",
"static/img/adopters/szzt.png": "Original retained for quality; card-sized variants are generated at build time.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nothing serves the 15000px szzt original since the biggest variant is 340px, pls downscale the src and drop this exemption.

Comment on lines +2 to +4
"static/img/adopters/ecloud.jpg": "Existing adopter logo; migrate through the responsive pipeline before changing it.",
"static/img/adopters/linkedin.png": "Existing adopter logo; migrate through the responsive pipeline before changing it.",
"static/img/adopters/pingan-securities.png": "Existing adopter logo; migrate through the responsive pipeline before changing it.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these logos got an exemption instead of the new pipeline, so #662 is only fixed for szzt.

@vivek-gite vivek-gite changed the title chore: update image handling and dependencies perf(media):: update image handling and dependencies Jul 30, 2026
@vivek-gite vivek-gite changed the title perf(media):: update image handling and dependencies perf(media): update image handling and dependencies Jul 30, 2026
…nsive variants. The full raster-size scan now runs as an explicit Docs Health CI step; it remains available locally via npm run images:check.
@hami-robot

hami-robot Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Thanks for your pull request. Before we can look at it, you'll need to add a 'DCO signoff' to your commits.

📝 Please follow instructions in the contributing guide to update your commits with the DCO

Full details of the Developer Certificate of Origin can be found at developercertificate.org.

The list of commits missing DCO signoff:

  • b5f6948 Updated images:prepare so local start/build hooks only generate responsive variants. The full raster-size scan now runs as an explicit Docs Health CI step; it remains available locally via npm run images:check.
Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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.

perf(media): serve raster images at an appropriate responsive size

2 participants