Repository navigation
Conversation
Add an ImageAdapter using Next.js Image with a validated iChef loader, used by Promo.Image behind the disabled nextJsImageAdapter toggle. It reuses the BFF's WebP URLs and matches existing promo widths. AMP, Lite, portrait and programme images keep the existing renderer. Refs: WS-3608
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Percent-encoded width templates leave generated URLs unresolved, and WebP overrides remove the original-format fallback, causing broken images in browsers without WebP support.
2 open issues
What changed in this PR
Trials a Next.js Image adapter for Simorgh promo images on Home, Topics and My News, following the earlier proof of concept. The trial is disabled in every environment and keeps iChef responsible for image delivery.
Changes:
- Adds an adapter with iChef source validation, responsive images, format fallback and placeholders.
- Gates eligible promo images behind a toggle, retaining the existing renderer for AMP, Lite, portrait and programme images.
- Configures promo image widths and adds tests and trial documentation.
| File | Description |
|---|---|
ws-nextjs-app/next.config.js |
Configures the promo image width ladder. |
src/app/lib/config/toggles/testConfig.js |
Disables the trial in test. |
src/app/lib/config/toggles/README.md |
Documents the trial toggle. |
src/app/lib/config/toggles/localConfig.js |
Disables the trial locally. |
src/app/lib/config/toggles/liveConfig.js |
Disables the trial in live. |
src/app/lib/config/toggles/__snapshots__/index.test.js.snap |
Records the disabled toggle across environments. |
src/app/legacy/components/Promo/index.test.jsx |
Adds renderer comparisons and loading checks. |
src/app/legacy/components/Promo/image.jsx |
Routes eligible promos through the toggled adapter. |
src/app/components/ImageAdapter/README.md |
Explains trial scope, API and BFF responsibilities. |
src/app/components/ImageAdapter/index.tsx |
Implements the Next.js Image wrapper. |
src/app/components/ImageAdapter/index.test.tsx |
Tests rendering, formats, loading and placeholders. |
src/app/components/ImageAdapter/index.module.scss |
Styles the image wrapper and placeholders. |
src/app/components/ImageAdapter/ichefLoader.ts |
Validates iChef templates and substitutes widths. |
src/app/components/ImageAdapter/ichefLoader.test.ts |
Tests source validation and width substitution. |
src/app/components/Curation/CurationPromo/index.test.tsx |
Tests toggle integration and excluded image paths. |
Review effort: Balanced
| !url.password && | ||
| !url.search && | ||
| !url.hash && | ||
| ACE_TEMPLATE_PATH.test(url.pathname), |
| const image = ( | ||
| <NextImage | ||
| src={fallbackTemplate} | ||
| overrideSrc={src.replace('{width}', String(FALLBACK_SRC_WIDTH))} |
This branch has not been deployed
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.

Resolves JIRA: WS-3608
Summary
Trials Next.js Image for promo images on Home, Topics and My News pages, as the first step in deciding whether it can simplify our shared image code. The new renderer is behind a toggle that is off in every environment, so nothing changes for users. With the toggle on, promos look the same and load the same image sizes from iChef as they do today.
Code changes
ImageAdapter, a small wrapper around Next.js Image with 8 props. Its custom loader only accepts iChef URLs and fills in the image width. iChef still resizes and delivers images; Next.js's own image optimiser isn't used.ImageAdapterinPromo.Imagewhen the newnextJsImageAdaptertoggle is on. AMP, Lite, portrait and programme images stay on the existingImagecomponent.images.deviceSizesinnext.config.jsto the existing promo widths (85–800px) so the iChef URLs don't change.Promo.ImageandCurationPromo. Update the toggle snapshot and the toggles README.Testing
yarn test:unitfrom the repo root, andyarn testfromws-nextjs-appfor the Next.js app tests.yarn devinws-nextjs-app, openhttp://localhost.bbc.com:7081/mundoand a topic page, and check promos render as before.nextJsImageAdaptertoenabled: trueinsrc/app/lib/config/toggles/localConfig.jsand restart the dev server so it picks up thenext.config.jschange.<img>elements havedata-nimgand use iChef URLs, with no/_next/imagerequests;.ampand.liteversions of the pages are unchanged.false.Locally, the adapter serves JPEG/PNG instead of WebP, because the local fixtures are older than the BFF's WebP URLs. Production data isn't affected.
The Home and Topics canonical integration tests have 7 snapshot failures against the dev server, caused only by a generated CSS class name. The same 7 fail on
latestwithout these changes.Useful Links