Skip to content

Revert "[WS-2817] Refactor toggles url" - #14281

Merged
HarveyPeachey merged 1 commit into
latestfrom
revert-14226-WS-2817-refactor-toggles-url
Jul 30, 2026
Merged

Revert "[WS-2817] Refactor toggles url"#14281
HarveyPeachey merged 1 commit into
latestfrom
revert-14226-WS-2817-refactor-toggles-url

Conversation

@HarveyPeachey

Copy link
Copy Markdown
Contributor

Reverts #14226

@HarveyPeachey HarveyPeachey self-assigned this Jul 30, 2026
Copilot AI review requested due to automatic review settings July 30, 2026 08:26

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.

Pull request overview

This PR reverts the toggle URL refactor from #14226 by moving toggle fetching away from TOGGLES_BFF_PATH/fetchToggles and back to using SIMORGH_CONFIG_URL, updating server-side routes and test tooling to read toggles from the config API and adding an LRU-cached wrapper.

Changes:

  • Replace fetchToggles usage across Next.js routes/pages with getToggles(service) via #app/lib/utilities/getToggles/withCache.
  • Introduce getToggles (config-API based) and withCache (LRUCache), and remove legacy fetchToggles and getToggle.
  • Update Playwright/Cypress toggle fetching URLs and AMP ads access config, plus related tests/snapshots and docs.

Reviewed changes

Copilot reviewed 38 out of 38 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
ws-nextjs-app/utilities/pageRequests/getPageData.test.ts Update mocks to align with getToggles module.
ws-nextjs-app/playwright/pageTypes/liveRadioPage/liveRadioPage.spec.ts Fetch toggles from config API for E2E suite (env-based URL mapping).
ws-nextjs-app/pages/[service]/onDemandTv/handleOnDemandTvRoute.ts Switch OnDemand TV route to cached getToggles.
ws-nextjs-app/pages/[service]/onDemandTv/handleOnDemandTvRoute.test.ts Update route tests to mock cached getToggles.
ws-nextjs-app/pages/[service]/onDemandAudio/handleOnDemandAudioRoute.ts Switch OnDemand Audio route to cached getToggles.
ws-nextjs-app/pages/[service]/my-news/index.page.tsx Switch My News SSR gating to cached getToggles.
ws-nextjs-app/pages/[service]/my-news/index.page.test.tsx Update My News tests to mock cached getToggles.
ws-nextjs-app/pages/[service]/liveRadio/handleLiveRadioRoute.ts Switch Live Radio route to cached getToggles and move toggle fetch earlier.
ws-nextjs-app/pages/[service]/liveRadio/handleLiveRadioRoute.test.ts Update Live Radio route tests to mock cached getToggles.
ws-nextjs-app/pages/[service]/downloads/[[...variant]].page.tsx Switch Downloads SSR to cached getToggles.
ws-nextjs-app/pages/_app.page.tsx Switch app-level toggles fetch to cached getToggles.
ws-nextjs-app/cypress/support/config/envs.ts Add togglesUrl to Cypress env config.
ws-nextjs-app/cypress/support/commands.ts Update Cypress toggle fetch to use config API + amp source origin.
src/app/utilities/createAdNonce/index.ts Replace getToggle usage with toggle-definition extraction.
src/app/lib/utilities/getToggles/withCache.test.js Add unit test for LRU-cached wrapper behavior.
src/app/lib/utilities/getToggles/withCache.js Add cached wrapper around getToggles using LRUCache.
src/app/lib/utilities/getToggles/index.js Add new config-API based toggle fetcher with optional cache integration.
src/app/lib/utilities/getToggles/index.client.test.js Add tests for default/remote/cached toggle merging and logging behavior.
src/app/lib/utilities/getToggleDefinition/index.ts Change utility to return toggle definitions sans _environment.
src/app/lib/utilities/getToggleDefinition/index.test.ts Add tests for _environment stripping behavior.
src/app/lib/utilities/getToggle/index.ts Remove legacy single-toggle getter.
src/app/lib/utilities/getToggle/index.test.ts Remove tests for legacy single-toggle getter.
src/app/lib/utilities/fetchToggles/index.ts Remove legacy fetchToggles implementation.
src/app/lib/utilities/fetchToggles/index.client.test.ts Remove tests for legacy fetchToggles.
src/app/lib/utilities/fetchConfig/index.ts Minor style simplification in cached return.
src/app/lib/logger.const.js Remove unused legacy toggle API log codes.
src/app/lib/idcta/getIdctaConfig/index.ts Update to use toggle-definition extraction utility.
src/app/lib/idcta/getIdctaConfig/index.test.ts Update tests to mock toggle-definition extraction.
src/app/lib/config/toggles/README.md Update docs links/references to point at getToggles.
src/app/contexts/ToggleContext/utils/constructTogglesEndpoint/index.ts Rework endpoint construction around SIMORGH_CONFIG_URL + __amp_source_origin.
src/app/contexts/ToggleContext/utils/constructTogglesEndpoint/index.test.ts Update endpoint-constructor tests for new URL shape.
src/app/components/Ad/index.test.tsx Remove WEB_CDN_URL env dependence from tests.
src/app/components/Ad/Amp/index.tsx Update AMP access endpoint construction + AMP access expression path.
src/app/components/Ad/Amp/index.test.tsx Update tests for new AMP access endpoint construction.
src/app/components/Ad/Amp/snapshots/index.test.tsx.snap Update snapshots for new amp-access expression path.
src/app/components/Ad/snapshots/index.test.tsx.snap Update AMP ad snapshots for new amp-access expression path.
scripts/checkSecretEnvVariables.sh Remove obsolete TOGGLES_BFF_PATH env check.
cypress.config.ts Remove TOGGLES_BFF_PATH injection into Cypress env.

Comment on lines +18 to +35
const logResponseTime = async (url, origin, service, timeout) => {
const response = await fetch(url, { headers: { origin }, timeout });

if (onClient()) {
return response;
}

logger.info(CONFIG_REQUEST_RECEIVED, { url, service });
const startHrTime = process.hrtime();
const elapsedHrTime = process.hrtime(startHrTime);
logger.info(TOGGLE_API_RESPONSE_TIME, {
nanoseconds: elapsedHrTime[0] * NS_PER_SEC + elapsedHrTime[1],
url,
service,
});

return response;
};
Comment on lines +41 to +45
const togglesUrlByEnv: Record<'local' | 'test' | 'live', string> = {
local: 'https://config.api.bbci.co.uk/',
test: 'https://config.test.api.bbci.co.uk/',
live: 'https://config.test.api.bbci.co.uk/',
};
Comment on lines 28 to 32
export const AMP_ACCESS_FETCH = (service: Services) => {
const togglesEndpoint = constructTogglesEndpoint({ service, isAmp: true });
const togglesEndpoint = `${
getEnvConfig().SIMORGH_CONFIG_URL
}?application=simorgh&service=${service}`;

Comment on lines +46 to +47
const { origin } = getOriginContext();
const url = constructTogglesEndpoint(service, origin);
@HarveyPeachey
HarveyPeachey merged commit 2ea0a52 into latest Jul 30, 2026
18 checks passed
@HarveyPeachey
HarveyPeachey deleted the revert-14226-WS-2817-refactor-toggles-url branch July 30, 2026 08:36
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.

4 participants