Add Next.js ISR cache, routes, and revalidation APIs - #14320
Open
HarveyPeachey wants to merge 4 commits into
Open
Add Next.js ISR cache, routes, and revalidation APIs#14320HarveyPeachey wants to merge 4 commits into
HarveyPeachey wants to merge 4 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds internal Next.js ISR support for article pages in the ws-nextjs-app, including a custom cache handler (memory/S3), rewrites to route selected services’ /articles/* traffic to an ISR-enabled page, and authenticated on-demand revalidation endpoints for both individual articles and whole services.
Changes:
- Added a custom Next.js
cacheHandlerimplementation with optional S3 backing and a service-level invalidation helper. - Introduced an ISR article route (
/articles-isr/*) plus rewrites for a rollout set of services driven bySIMORGH_ISR_ROLLOUT_SERVICES. - Added authenticated
/api/revalidate/articleand/api/revalidate/serviceendpoints with unit tests and a shared auth utility.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| ws-nextjs-app/utilities/revalidation/auth.ts | Shared logic to extract/validate the revalidation secret from header or query string. |
| ws-nextjs-app/pages/api/revalidate/service/index.api.ts | Service-wide cache invalidation API endpoint using the cache handler helper. |
| ws-nextjs-app/pages/api/revalidate/service/index.api.test.ts | Unit tests covering auth + required params + happy path for service invalidation. |
| ws-nextjs-app/pages/api/revalidate/article/index.api.ts | Article path on-demand revalidation endpoint using res.revalidate. |
| ws-nextjs-app/pages/api/revalidate/article/index.api.test.ts | Unit tests for auth/validation and successful article revalidation response payload. |
| ws-nextjs-app/pages/[service]/articles-isr/handleArticleRouteStatic.ts | New static data handler for ISR article pages (fetch + shouldRender + props shaping). |
| ws-nextjs-app/pages/[service]/articles-isr/[[...variant]].page.tsx | ISR article page entrypoint with getStaticPaths seeded from Most Read and fallback: 'blocking'. |
| ws-nextjs-app/package.json | Dependency changes related to ISR/cache handler wiring (currently contains merge conflict markers). |
| ws-nextjs-app/next.config.js | Wires custom cache handler + adds rewrites for rollout services from env var. |
| ws-nextjs-app/cache-handler.js | New Next.js cache handler implementation with in-memory and optional S3 storage + service invalidation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+81
to
83
| <<<<<<< HEAD | ||
| "@aws-sdk/client-s3": "3.919.0", | ||
| "autoprefixer": "10.5.4", |
Comment on lines
+114
to
+122
| const { | ||
| topStories = null, | ||
| features = null, | ||
| latestMedia = null, | ||
| mostRead = null, | ||
| billboardCuration = null, | ||
| mediaCuration = null, | ||
| portraitVideoItems = null, | ||
| } = secondaryData || {}; |
Comment on lines
+45
to
+66
| export default async (context: GetStaticPropsContext<Params>) => { | ||
| const pathname = buildCanonicalPathname(context.params); | ||
|
|
||
| if (!pathname) { | ||
| return { | ||
| notFound: true, | ||
| }; | ||
| } | ||
|
|
||
| const { service } = context.params as Params; | ||
|
|
||
| const { isAmp } = getPathExtension(pathname); | ||
| const { variant } = parseRoute(pathname); | ||
|
|
||
| const { data } = await getPageData({ | ||
| id: pathname, | ||
| service, | ||
| variant: variant || undefined, | ||
| resolvedUrl: pathname, | ||
| pageType: ARTICLE_PAGE, | ||
| isAmp, | ||
| }); |
Comment on lines
+19
to
+25
| const cache = new Map(); | ||
| const serviceKeyIndex = new Map(); | ||
|
|
||
| const ARTICLE_SERVICE_REGEX = /\/([a-z0-9-]+)\/articles\//i; | ||
|
|
||
| const cacheBackend = (process.env.SIMORGH_ISR_CACHE_BACKEND || 'memory').trim(); | ||
| const cacheBucket = process.env.SIMORGH_ISR_CACHE_BUCKET; |
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.
Summary
This introduces Next.js internal ISR support for article pages and wires secure on-demand revalidation so content updates can invalidate cached pages without full redeploys.
Code changes
latestinto the branch and resolved dependency conflicts inws-nextjs-app/package.json.Testing
Useful links
nextjs-internal-isr