Skip to content

Refactor: replace CodeLangToggle with CodeExampleClient for improved (#430)#431

Open
vaibhav0725 wants to merge 1 commit into
usesend:mainfrom
vaibhav0725:enhance/language-box-ui-betterment
Open

Refactor: replace CodeLangToggle with CodeExampleClient for improved (#430)#431
vaibhav0725 wants to merge 1 commit into
usesend:mainfrom
vaibhav0725:enhance/language-box-ui-betterment

Conversation

@vaibhav0725

@vaibhav0725 vaibhav0725 commented Jul 19, 2026

Copy link
Copy Markdown

Closes #430

Summary:

Adds a smooth height animation when switching languages in the homepage Developers code example. The block no longer snaps between sizes.

  • Introduces CodeExampleClient to measure active panel height and animate with transition-[height] duration-300 ease-in-out
  • Refactors LangToggle to controlled props (active / onActiveChange) instead of DOM classList toggling
  • Keeps CodeBlock (async Shiki) on the server; client wrapper only handles toggle + animation

Test plan

  • Open marketing homepage → Developers section
  • Switch between TypeScript, Python, Go, PHP
  • Confirm code block expands/shrinks smoothly (~300ms ease-in-out)
  • Confirm no layout flash on first load
  • Confirm copy button still works on each language panel
Screen.Recording.2026-07-19.at.8.31.26.PM.mov

Summary by cubic

Replace CodeLangToggle with CodeExampleClient to add a smooth height animation when switching languages in the homepage Developers code example. The code block now resizes smoothly (~300ms) without snapping or flicker.

  • Refactors
    • Introduced CodeExampleClient to control active language and measure panel height for a 300ms transition.
    • Kept Shiki rendering on the server via CodeBlock/CodeBlockWithCopy; pass pre-rendered panels into the client.
    • Updated LangToggle to controlled active/onActiveChange; removed DOM classList manipulation.

Written for commit b58d353. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Enhancements

    • Improved code example language switching with smoother panel transitions.
    • Added accessible announcements when changing the displayed language.
    • Code examples now adapt more reliably to content size across languages.
  • Refactor

    • Updated language toggles to provide a more consistent and responsive code-example experience.

@vercel

vercel Bot commented Jul 19, 2026

Copy link
Copy Markdown

@vaibhav0725 is attempting to deploy a commit to the kmkoushik's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

CodeExample now asynchronously prepares language-specific code panels and delegates interactive rendering to CodeExampleClient. The client component controls the active language, measures panel height with ResizeObserver, applies animated height changes, and announces toggles to screen readers. LangToggle was updated to use controlled active and onActiveChange props.

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR adds a client wrapper with measured height transitions and keeps CodeBlock async, matching the issue's animation goals.
Out of Scope Changes check ✅ Passed The changes stay focused on the code example toggle and animation refactor with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change by describing the replacement of CodeLangToggle with CodeExampleClient.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
apps/marketing/src/components/CodeExampleClient.tsx (1)

6-10: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate LangItem type — consolidate into one shared definition.

LangItem is independently redefined here; CodeLangToggle.tsx already declares a structurally similar (but not identical) LangItem. Keeping two copies risks silent drift as fields change.

♻️ Proposed fix
-type LangItem = {
-  key: string;
-  label: string;
-  kind: string;
-};
+import type { LangItem } from "./CodeLangToggle";

(requires exporting LangItem from CodeLangToggle.tsx)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/marketing/src/components/CodeExampleClient.tsx` around lines 6 - 10,
Remove the local LangItem definition from CodeExampleClient.tsx and reuse the
exported LangItem type from CodeLangToggle.tsx. Export the existing shared
definition, then update the import and any usages in CodeExampleClient to
reference it without changing behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/marketing/src/components/CodeExample.tsx`:
- Around line 117-129: Remove the `as any` cast from the `lang` prop in the
`CodeBlock` usage within the `panels` mapping, passing `l.shiki` directly.
Preserve the existing language values and rendering behavior while relying on
`CodeBlock`’s `BundledLanguage | "text"` type validation.

In `@apps/marketing/src/components/CodeExampleClient.tsx`:
- Around line 63-65: Update the language-toggle announcement in
CodeExampleClient so the aria-live region’s text changes whenever the selected
language changes, rather than rendering the static “Language example toggled”
text. Reuse the existing language state or toggle handler to include the current
language in the announcement while preserving the sr-only and polite live-region
behavior.

---

Nitpick comments:
In `@apps/marketing/src/components/CodeExampleClient.tsx`:
- Around line 6-10: Remove the local LangItem definition from
CodeExampleClient.tsx and reuse the exported LangItem type from
CodeLangToggle.tsx. Export the existing shared definition, then update the
import and any usages in CodeExampleClient to reference it without changing
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aa3c1595-8c1d-49a2-aba5-8ad458242382

📥 Commits

Reviewing files that changed from the base of the PR and between 89cba7f and b58d353.

📒 Files selected for processing (3)
  • apps/marketing/src/components/CodeExample.tsx
  • apps/marketing/src/components/CodeExampleClient.tsx
  • apps/marketing/src/components/CodeLangToggle.tsx

Comment on lines +117 to +129
const panels = Object.fromEntries(
await Promise.all(
languages.map(async (l) => [
l.key,
<CodeBlockWithCopy key={l.key} code={l.code}>
<CodeBlock lang={l.shiki as any} className="p-4 rounded-[10px]">
{l.code}
</CodeBlock>
</CodeBlockWithCopy>,
])
)
);

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
fd code-block.tsx packages/ui --exec cat -n {} \; 2>/dev/null | sed -n '1,20p'
rg -n "type Props" packages/ui/src/code-block.tsx -A 8

Repository: usesend/useSend

Length of output: 828


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== apps/marketing/src/components/CodeExample.tsx ==\n'
cat -n apps/marketing/src/components/CodeExample.tsx | sed -n '1,180p'

printf '\n== shiki language references in repo ==\n'
rg -n '"typescript"|"python"|"go"|"php"|BundledLanguage' . -g '!**/node_modules/**' -g '!**/.next/**' -g '!**/dist/**' -g '!**/build/**' | sed -n '1,120p'

Repository: usesend/useSend

Length of output: 7623


Remove the as any cast on lang. CodeBlock already accepts BundledLanguage | "text", so this only weakens type safety and can hide future language mismatches.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/marketing/src/components/CodeExample.tsx` around lines 117 - 129, Remove
the `as any` cast from the `lang` prop in the `CodeBlock` usage within the
`panels` mapping, passing `l.shiki` directly. Preserve the existing language
values and rendering behavior while relying on `CodeBlock`’s `BundledLanguage |
"text"` type validation.

Comment on lines +63 to +65
<div className="sr-only" aria-live="polite">
Language example toggled
</div>

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Static aria-live text never triggers a screen-reader announcement.

Screen readers announce live regions only when their content changes. This text is hardcoded and identical on every render, so switching languages never actually announces anything to assistive tech, despite that being the intent of this region.

🔊 Proposed fix
+  const activeLabel =
+    languages.find((l) => l.key === activeLang)?.label ?? activeLang;
+
   return (
     <>
       ...
       <div className="sr-only" aria-live="polite">
-        Language example toggled
+        Showing {activeLabel} example
       </div>
     </>
   );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div className="sr-only" aria-live="polite">
Language example toggled
</div>
const activeLabel =
languages.find((l) => l.key === activeLang)?.label ?? activeLang;
return (
<>
<div className="sr-only" aria-live="polite">
Showing {activeLabel} example
</div>
</>
);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/marketing/src/components/CodeExampleClient.tsx` around lines 63 - 65,
Update the language-toggle announcement in CodeExampleClient so the aria-live
region’s text changes whenever the selected language changes, rather than
rendering the static “Language example toggled” text. Reuse the existing
language state or toggle handler to include the current language in the
announcement while preserving the sr-only and polite live-region behavior.

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.

[Enhancement]-UI Enhancing on the landing page(Typed SDKs and simple APIs-Section)

1 participant