Skip to content

WS-3608: trial Next.js Image adapter in promo images - #14730

Draft
vdeksne wants to merge 1 commit into
latestfrom
ws-3608-nextjs-image
Draft

vdeksne wants to merge 1 commit into
latestfrom
ws-3608-nextjs-image

Conversation

@vdeksne

@vdeksne vdeksne commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Add 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.
  • Use the WebP URLs the BFF already prepares, with the original JPEG/PNG as the fallback. No new URL-building logic is added in the frontend.
  • Use ImageAdapter in Promo.Image when the new nextJsImageAdapter toggle is on. AMP, Lite, portrait and programme images stay on the existing Image component.
  • Set images.deviceSizes in next.config.js to the existing promo widths (85–800px) so the iChef URLs don't change.
  • Add tests for the loader and adapter, plus toggle-off/on comparisons for Promo.Image and CurationPromo. Update the toggle snapshot and the toggles README.
  • Add the adapter README: the list of image components, the agreed trial set, prop decisions and BFF notes.

Testing

  1. Run yarn test:unit from the repo root, and yarn test from ws-nextjs-app for the Next.js app tests.
  2. With the toggle off, run yarn dev in ws-nextjs-app, open http://localhost.bbc.com:7081/mundo and a topic page, and check promos render as before.
  3. Set nextJsImageAdapter to enabled: true in src/app/lib/config/toggles/localConfig.js and restart the dev server so it picks up the next.config.js change.
  4. Reload both pages and check that:
    • promos look the same at mobile and desktop widths;
    • promo <img> elements have data-nimg and use iChef URLs, with no /_next/image requests;
    • the .amp and .lite versions of the pages are unchanged.
  5. Set the toggle back to 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 latest without these changes.

Useful Links

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
Copilot AI balanced review requested due to automatic review settings November 28, 2026 06:34
@vdeksne
vdeksne marked this pull request as draft November 28, 2026 06:34

Copilot AI 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.

🟡 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

No deployments
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.

2 participants