Skip to content

Conversation

@richardsolomou
Copy link
Member

@richardsolomou richardsolomou commented Jan 29, 2026

Changes

Adds persistent, synchronized tab selections for code blocks in documentation. When a user selects a preference (e.g. pnpm instead of npm, or Python instead of Node), that preference now:

  • Persists across page refreshes via localStorage
  • Syncs in real-time across all code blocks with the same syncKey on the page
  • Applies across different pages (e.g. select Python once, see Python everywhere)
  • Falls back to first option if stored preference doesn't match any available option

This is opt-in via the syncKey prop on MultiLanguage components.

How it works:

  1. New codeBlockLogic.ts uses kea with { persist: true } for automatic localStorage persistence
  2. MdxCodeBlock conditionally renders SyncedCodeBlock when syncKey is provided
  3. Multiple code blocks with the same syncKey stay in sync across the page
  4. User preferences are stored and restored on page load

Sync keys used:

  • install - package managers (npm/yarn/pnpm) - 4 code blocks
  • sdk-backend - backend SDKs (node/python/php/ruby/go/java) - 19 code blocks
  • sdk-client - frontend SDKs (js-web/ios/android/react-native) - 7 code blocks
  • api - curl/API examples - 10 code blocks

Test plan:

  • Visit a docs page with multiple code blocks (e.g. SDK installation)
  • Select a non-default option (e.g. pnpm instead of npm)
  • Verify the selection syncs to other code blocks with the same syncKey on the same page
  • Refresh the page and verify the selection persists
  • Visit a different page with the same syncKey and verify the selection is remembered
  • Verify code blocks without a matching option fall back to first option

Checklist

  • I've read the docs and/or content style guides.
  • Words are spelled using American English
  • Use relative URLs for internal links
  • I've checked the pages added or changed in the Vercel preview build
  • If I moved a page, I added a redirect in vercel.json

Add kea-based persistence for MultiLanguage code block tab selections.
When a user selects a preference (e.g. pnpm instead of npm, or Python
instead of Node), that preference now:

- Persists across page refreshes via localStorage
- Syncs in real-time across all code blocks with the same syncKey

This is opt-in via the syncKey prop on MultiLanguage components.

Sync key categories:
- install: package managers (npm/yarn/pnpm)
- sdk-backend: backend SDKs (node/python/php/ruby/go/java)
- sdk-client: frontend SDKs (js-web/ios/android/react-native)
- sdk: mixed frontend+backend SDK examples
- api: curl/API examples
- llm: LLM analytics (python/typescript)
- typescript: JS/TS file examples
@vercel
Copy link

vercel bot commented Jan 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
posthog Error Error Jan 29, 2026 9:15am

Request Review

- Remove syncKey="sdk" from 5 files (mixed frontend+backend doesn't make sense to sync)
- Remove syncKey="typescript" from 2 files (too niche, only 3 uses)
- Add fallback logic: if stored preference doesn't match any option, default to first

Final syncKeys (5 total):
- install (4): package managers
- sdk-backend (7): server-side SDKs
- sdk-client (7): client-side SDKs
- api (10): curl/API examples
- llm (12): LLM analytics
- Change syncKey='llm' to syncKey='sdk-backend' in 6 LLM analytics files
- Replace typescript/javascript language identifiers with node
- Add syncKey='sdk-backend' to helicone integration file
- Reorder code blocks to show node first for consistency

This reduces the number of sync keys from 5 to 4:
- sdk-backend: 19 uses
- api: 10 uses
- sdk-client: 7 uses
- install: 4 uses
The kea-localstorage plugin requires logic to have a unique path
when using persist: true. Without it, the error '[KEA] Logic must
have a unique path to persist reducers' is thrown.
- Log when SyncedCodeBlock renders with preferences
- Log when handleChange is called
- Fix useEffect to trigger on preferences[syncKey] changes
- This should help diagnose why stored preferences aren't being restored
@richardsolomou richardsolomou marked this pull request as draft January 29, 2026 08:12
The CodeBlock component has internal selectedIndex state that wasn't
being synced with the currentLanguage prop. This caused the tabs to
show the wrong language as selected even when currentLanguage state
was correct.

Added useEffect to sync selectedIndex whenever currentLanguage changes.
Fixed issue where multiple code blocks with the same syncKey on the
same page weren't syncing when one was changed. The useEffect now
properly depends on storedPreference, languages, and currentLanguage
to trigger updates when any code block with the same syncKey changes.

Also removed all debug console.log statements.
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