Skip to content

RDoc-3454 Persist selected language in URL#2561

Open
poissoncorp wants to merge 1 commit into
ravendb:mainfrom
poissoncorp:RDoc-3454-persist-language-in-url
Open

RDoc-3454 Persist selected language in URL#2561
poissoncorp wants to merge 1 commit into
ravendb:mainfrom
poissoncorp:RDoc-3454-persist-language-in-url

Conversation

@poissoncorp

Copy link
Copy Markdown
Contributor

Issue link

RDoc-3583 Persist selected language state in the URL
RDoc-3454 Language switcher should open the article in a new tab on Ctrl+Click

Additional description

Make the "?lang=" query parameter the per-tab source of truth for the selected API language, so a page can be shared/linked in a specific language and two tabs can show different languages side-by-side. On Ctrl+Click, a new tab appears with the clicked language.

Type of change

  • Content - docs
  • Content - cloud
  • Content - guides
  • Content - start pages/other
  • New docs feature (consider updating /templates or readme)
  • Bug fix
  • Optimization
  • Other

Changes in docs URLs

  • No changes in docs URLs
  • Articles are restructured, URLs will change, mapping is required (update /scripts/redirects.json file, set Documents Moved PR label)

Changes in UX/UI

  • No changes in UX/UI
  • Changes in UX/UI (include screenshots and description)

…l+Click

Make the "?lang=" query parameter the per-tab source of truth for the
selected API language, so a page can be shared/linked in a specific
language and two tabs can show different languages side-by-side.

- LanguageStore: the useSyncExternalStore snapshot reads the URL first,
  then the stored (localStorage) cross-session default, then csharp; the
  server snapshot is the default so the first render matches the
  prerendered HTML. setLanguage writes both localStorage and the URL
  (default kept out of the URL) and notifies same-tab only (a custom
  event, not the native "storage" event), so switching in one tab no
  longer flips other tabs.
- LanguageUrlSync (new): mounted on pages with supported_languages;
  persists an incoming "?lang=" and re-stamps it after navigation
  (internal links drop the query string).
- LanguageSwitcher: options are anchors to the current page with an
  explicit "?lang="; plain click switches in place, Ctrl/Cmd/Shift/middle
  click opens the language in a new tab/window (RDoc-3454).
@poissoncorp
poissoncorp requested review from Lwiel and kalczur July 16, 2026 11:23
setLanguage: (newLanguage: DocsLanguage) => void;
} => {
const language = useSyncExternalStore(subscribe, getLanguageFromLocalStorage, () => DEFAULT_LANGUAGE);
const history = useHistory();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL hash changes (TOC clicks) now re-render every language block

const { setLanguage } = useLanguage();
const location = useLocation();

useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now you can remove useEffect from LanguageSwitcher.tsx

@kalczur

kalczur commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

@poissoncorp
To consider:
A Node.js user who browses a C# only page silently gets their global preference reset to C#, and later pages that supports Node.js open in C#. It would be better to update global preference only on user intended click.

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.

3 participants