Revert "[WS-2817] Refactor toggles url" - #14281
Merged
Merged
Conversation
elvinasv
approved these changes
Jul 30, 2026
Isabella-Mitchell
approved these changes
Jul 30, 2026
Contributor
There was a problem hiding this comment.
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
fetchTogglesusage across Next.js routes/pages withgetToggles(service)via#app/lib/utilities/getToggles/withCache. - Introduce
getToggles(config-API based) andwithCache(LRUCache), and remove legacyfetchTogglesandgetToggle. - 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); |
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.
Reverts #14226