fix(web): persist locale cookie on canonical docs pages#15938
Open
zerone0x wants to merge 1 commit intoanomalyco:devfrom
Open
fix(web): persist locale cookie on canonical docs pages#15938zerone0x wants to merge 1 commit intoanomalyco:devfrom
zerone0x wants to merge 1 commit intoanomalyco:devfrom
Conversation
The oc_locale cookie was only written when the middleware triggered a redirect through docsAlias() — i.e., when a user visited an alias URL like /docs/en/page. Canonical locale paths (e.g. /docs/tr/page) and the English root path (e.g. /docs/page) never wrote the cookie. This meant that switching language via the Starlight language switcher had no lasting effect: clicking English navigated to /docs/page, but no cookie was set. The next visit to /docs/ re-read Accept-Language from the browser and redirected back to the non-English locale. Fix: detect the locale from the URL path on every docs page request and write the oc_locale cookie whenever the current cookie value differs. This makes the language switcher choice sticky across navigations without requiring an alias redirect. Closes anomalyco#15845 Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential duplicate found:
Why it might be related: |
IgorTavcar
added a commit
to IgorTavcar/opencode
that referenced
this pull request
Mar 4, 2026
) Cherry-picked from upstream PR anomalyco#15938. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Issue for this PR
Closes #15845
Type of change
What does this PR do?
The language switcher on opencode.ai/docs doesn't stick when switching to English (or any locale via the Starlight switcher).
Root cause: the
oc_localecookie was only written in one place — insidedocsAlias(), which triggers on alias URLs like/docs/en/pageand redirects to the canonical path. The Starlight language switcher generates canonical URLs directly (e.g./docs/pagefor English,/docs/tr/pagefor Turkish), so the cookie was never written when switching language this way. On the next visit to/docs/, the middleware re-readAccept-Languagefrom the browser and redirected back to the original locale.The fix detects the locale from the URL path on every docs page request and appends the
oc_localecookie to the response when the current cookie value differs. This makes the language switcher choice sticky without requiring any Starlight or build-time changes.How did you verify your code works?
Traced the middleware logic manually:
/docs/tr/page→ setsoc_locale=trif cookie differs/docs/page→ infers root/English (no locale prefix →exactLocalereturns null → "root") → setsoc_locale=en/docs/→ reads cookie → no redirect ✓Screenshots / recordings
N/A — middleware logic change, no visual output.
Checklist