Repository navigation
Conversation
The server-side page caches (bot cache, enabled by default, and the anonymous cache) were keyed by req.url only. The language of an SSR render depends on the dsLanguage cookie and the Accept-Language header, so a page rendered in one language was served from the cache to visitors who asked for another one. The key is now the URL followed by the language the request is rendered in, resolved the same way LocaleService/ServerLocaleService do for anonymous requests (active cookie language, then the first active Accept-Language entry, then the fallback language). Using the resolved language instead of the raw header keeps header variants that ask for the same language in one cache entry. The key still starts with the URL, so /reload paths are still excluded from caching. The key logic moves to src/app/core/locale/ssr-cache-key.ts so it can be unit tested.
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.
References
getCacheKey()come from Add Caching of SSR public pages. Update default Cache-Control HTTP header #2033req.url. Both PRs changegetCacheKey(), so whichever is merged second needs a small rebase.Description
The in-memory SSR caches in
server.ts(the bot cache is on by default) use onlyreq.urlas the key. The language of an SSR render comes from thedsLanguagecookie or theAccept-Languageheader, so crawlers get a page in the language of the first anonymous visitor (human or bot) for up to a day (bot cache timeToLive). With the anonymous cache enabled, other visitors get it too.The cache key now also contains the language the request is rendered in, e.g.
/home|en.Instructions for Reviewers
List of changes in this PR:
server.ts:getCacheKey()now returns<url>|<language>(e.g./home|en) instead of<url>. The key still starts with the URL, so the/reloadexclusion is unchanged.src/app/core/locale/ssr-cache-key.tsbuilds the key. The language is resolved the same way SSR picks it for anonymous requests: an activedsLanguagecookie, else the first activeAccept-Languageentry, elsefallbackLanguage. Sodeandde-DE,de;q=0.9share one cache entry. It is outsideserver.tsso Karma can test it.ssr-cache-key.spec.ts.Trade-off: the helper copies SSR's language resolution instead of changing it, so this stays a key-only fix; the spec pins the helper's behaviour. Memory stays bounded by max, but on a multilingual site the same max covers fewer distinct URLs. No new configuration.
How to reproduce (default
config/config.yml, REST = sandbox.dspace.org, bot cache on by default):/homeas a crawler, first in German, then in English:langattribute:lang="de", thenlang="de". The English request got the cached German page.lang="de", thenlang="en".To run it again, restart the server first (this empties the cache). The cookie
-H 'Cookie: dsLanguage=de'instead ofAccept-Language: degives the same result.Spec:
npm test -- --include src/app/core/locale/ssr-cache-key.spec.tsAffected branches:
dspace-10_x,dspace-9_xanddspace-8_xhave the same key and the bot cache on by default, so I'd ask forport tolabels for those. The change applies cleanly todspace-10_x. On dspace-9_x and dspace-8_x, the @dspace/* path aliases don't exist (and dspace-8_x uses defaultLanguage instead of fallbackLanguage), so they need small manual ports, which I'm happy to open.AI Disclosure (REQUIRED)
Were AI tools used in the creation of this PR?
Claude Code (Opus 5.5) helped me reproduce the bug on
main, write the patch and the spec, and draft this description. I reviewed the change, checked that the helper matches theLocaleServicelogic, and ran the spec and the before/after reproduction above locally.Checklist
mainbranch of code (unless it is a backport or is fixing an issue specific to an older branch).npm run lintnpm run check-circ-deps)package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.