Skip to content

TUL/fix(ssr): don't cache non-2XX responses (soft-404 on unknown pages) - #1463

Closed
Kasinhou wants to merge 1 commit into
customer/TULfrom
tul/fix-soft-404-cache
Closed

TUL/fix(ssr): don't cache non-2XX responses (soft-404 on unknown pages)#1463
Kasinhou wants to merge 1 commit into
customer/TULfrom
tul/fix-soft-404-cache

Conversation

@Kasinhou

@Kasinhou Kasinhou commented Aug 18, 2026

Copy link
Copy Markdown

Fixes soft-404 on tul: an unknown route / /static/<missing> renders the 404 page but the SSR cache replayed it as HTTP 200. saveToCache() stored the rendered page without checking status; serving a cached copy (res.send(cachedCopy)) does not restore the status. Add the hasNotSucceeded guard (as on dtq-dev/jcu) so non-2XX responses are never cached. tul has no StaticPageComponent, so both notFoundPage tests (route + static) share this 404 route and this one fix covers both. Note: a one-time redeploy clears the stale 200 cache entries; the guard prevents recurrence. Refs dataquest-dev/dspace-customers#566
566-tul-static-404
566-tul-route-404

An unknown route or `/static/<missing>` page renders the 404 page correctly,
but `saveToCache()` stored that rendered page in the bot/anonymous SSR cache
without checking the status code. On the next request the cached copy was
replayed via `res.send(cachedCopy)` (which does not restore the status), so a
correct 404 turned into HTTP 200 - a soft-404. UNIVERSAL-016 (dspace-ui-tests
notFoundPage.spec.ts, both "non-existent route" and "non-existent static page")
therefore failed on tul with 200 for the well-known test URIs, while a
fresh/cache-busted path still returned 404.

Skip caching when the response status is not 2XX (add the `hasNotSucceeded`
guard already used on dtq-dev/jcu). The 404 page is then never cached and can
no longer be served as 200.

Note: a redeploy/restart is still needed once to clear the stale 200 entries
already sitting in the in-memory cache; this guard prevents them recurring.

Refs dataquest-dev/dspace-customers#566

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

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 prevents SSR from caching rendered error pages (notably 404s) so that cached content can’t later be replayed with an incorrect HTTP 200 status (“soft-404”) in the TUL deployment.

Changes:

  • Add a guard in saveToCache() to skip caching when the current response status is not successful (non-2xx).
  • Introduce a hasNotSucceeded() helper intended to detect non-2xx status codes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread server.ts
Comment on lines +470 to +473
function hasNotSucceeded(statusCode) {
const rgx = new RegExp(/^20+/);
return !rgx.test(statusCode);
}
@Kasinhou Kasinhou closed this Aug 20, 2026
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