perf(ui-samples): serve mobile sample cards through next/image - #758
Open
dgaponov wants to merge 1 commit into
Open
perf(ui-samples): serve mobile sample cards through next/image#758dgaponov wants to merge 1 commit into
dgaponov wants to merge 1 commit into
Conversation
The mobile UI-samples cards rendered a plain <img> pointing straight at the
imported asset, bypassing the image optimizer that the rest of the page
already uses. The sources are up to 2212px wide while the cards display at
roughly viewport width, so the originals were served in full.
Pass the imported StaticImageData to next/image instead of just its `.src`,
so the images are resized per device and converted to WebP/AVIF.
Measured on the homepage at a 390px viewport, production build, fresh
profile, all seven cards scrolled into view:
card images 1234 kB -> 305 kB (-929 kB, -75%)
hotel-booking 329 -> 72 listing 126 -> 28
dashboard 189 -> 32 osn 126 -> 40
mail 183 -> 52 kubernetes 120 -> 34
task-tracker 163 -> 46
The cards also had no alt attribute at all. They now use the sample's
localised title ("Dashboard", "Booking page", ...), which the block already
had available.
The SCSS needs `width: 100%; height: auto` because next/image emits
intrinsic width/height attributes; without it the card laid out at the
source image's natural width of 2216px instead of the container's 508px.
That was caught in a browser and fixed, not shipped.
Desktop is unaffected: the block is display:none above the sm breakpoint and
issues zero card requests there, before and after.
Build, lint and typecheck pass. E2E not run - Playwright browsers are not
installed locally; these are visual changes, so the snapshot suite is worth
running before merge.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
dgaponov
marked this pull request as ready for review
September 11, 2026 08:35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Карточки UI-семплов рендерились обычным
<img>напрямую из ассета, минуя оптимизатор, который остальная страница уже использует. Исходники до 2212px шириной, отображаются примерно во всю ширину вьюпорта. Блок скрыт выше брейкпоинтаsm, поэтому лишний мегабайт платили только мобильные пользователи.Главная на 390px, прод-сборка, все семь карточек: 1234 → 305 КБ (−75%). Худшая, hotel-booking, 329 → 72 КБ.
Заодно у карточек не было
alt— теперь используется локализованный заголовок семпла.width: 100%; height: autoв SCSS обязателен: next/image проставляет атрибуты размеров, без этого карточка раскладывалась в натуральные 2216px вместо 508px.Десктоп не затронут — запросов карточек ноль до и после. E2E эту правку не покрывает: снапшот снимается на десктопе, где блок скрыт. Проверял вручную на 390px.
🤖 Generated with Claude Code