feat(code-block): add word wrap functionality and controls to code bl…#39689
Conversation
|
@Priyanshuthapliyal2005 is attempting to deploy a commit to the Supabase Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
|
Thanks for contributing to Supabase! ❤️ Our team will review your PR. A few tips for a smoother review process:
|
|
@charislam @saltcod would love your review. |
|
@Priyanshuthapliyal2005 Thanks! We are looking… Nice PR! |
|
Thanks for you contribution @Priyanshuthapliyal2005 ! This looks nice. I just see one issue: The line count gets messed up when word wrapping Se how the line 15 takes line 16 as well. Ideally, it should look like this (made randomly with devtools):
|
…ber display and structure
|
@stylessh I’ve fixed it. earlier line numbers and code were in separate columns, now each pair is wrapped in a single grid row for proper alignment. |
|
Thanks @Priyanshuthapliyal2005! Just a final nit: Make sure the red box is filled with the gray bg, the line count should have h-full, same at the bottom.
|
|
hi @stylessh , i have fixed the issue. Please re-review when you get a chance. |
ca4d2fa to
86d5ece
Compare
|
@Priyanshuthapliyal2005 Could you fix the prettier errors or give me write access to your fork / PR to do it myself and we can get this merged. |
WalkthroughIntroduces a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–25 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
|
Hi @ChrisChinchilla , I’ve fixed the Prettier error. Could you please review it? |
There was a problem hiding this comment.
Pull request overview
This PR adds a word wrap toggle button to code blocks in the documentation site, addressing issue #39421 where long commands and outputs require horizontal scrolling. The implementation uses a grid layout for line numbers, a new control component with wrap/unwrap buttons, and CSS to handle the wrapping behavior.
Key Changes:
- Restructured code block layout from flexbox to CSS grid to better support word wrapping with line numbers
- Added a new
CodeBlockControlscomponent that provides both word wrap toggle and copy functionality - Applied CSS rules to hide horizontal overflow and enable word wrapping when the wrap state is active
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| apps/docs/features/ui/CodeBlock/CodeBlock.tsx | Refactored layout from flexbox to CSS grid for line numbers; replaced individual CodeCopyButton with CodeBlockControls component |
| apps/docs/features/ui/CodeBlock/CodeBlock.client.tsx | Added CodeBlockControls component with word wrap toggle functionality and state management; added WrapText and ArrowRightFromLine icon imports |
| apps/docs/styles/main.scss | Added CSS rules to handle word wrapping behavior when data-wrapped attribute is set |
Comments suppressed due to low confidence (1)
apps/docs/features/ui/CodeBlock/CodeBlock.client.tsx:8
- Unused import getFontStyle.
import { getFontStyle } from './CodeBlock.utils'
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .shiki[data-wrapped='true'] .code-content { | ||
| overflow-x: hidden !important; | ||
| white-space: pre-wrap !important; | ||
| word-break: break-word !important; |
There was a problem hiding this comment.
The word-break property is set to 'break-word', which is a legacy value. Consider using the more modern and correct 'overflow-wrap: break-word' instead, or 'word-break: break-all' if you want to break within words at any character.
| word-break: break-word !important; | |
| overflow-wrap: break-word !important; |
| overflow-x: hidden !important; | ||
| white-space: pre-wrap !important; | ||
| word-break: break-word !important; |
There was a problem hiding this comment.
The CSS selector targets '.code-content' class but uses '!important' rules which can make future styling overrides difficult. Since this is a new feature, consider whether '!important' is necessary or if the selectors can be made more specific instead.
| overflow-x: hidden !important; | |
| white-space: pre-wrap !important; | |
| word-break: break-word !important; | |
| overflow-x: hidden; | |
| white-space: pre-wrap; | |
| word-break: break-word; |
| <code className={lineNumbers ? 'grid grid-cols-[auto_1fr]' : ''}> | ||
| {lineNumbers ? ( | ||
| <> | ||
| {tokens.map((line, idx) => ( | ||
| <Fragment key={idx}> | ||
| <div | ||
| className={cn( | ||
| 'select-none text-right text-muted bg-control px-2 min-h-5 leading-5', | ||
| idx === 0 && 'pt-6', | ||
| idx === tokens.length - 1 && 'pb-6' | ||
| )} | ||
| > | ||
| {idx + 1} | ||
| </div> | ||
| <div | ||
| className={cn( | ||
| 'code-content min-h-5 leading-5 pl-6 pr-6', | ||
| idx === 0 && 'pt-6', | ||
| idx === tokens.length - 1 && 'pb-6' | ||
| )} | ||
| > | ||
| <CodeLine tokens={line} twoslash={twoslashed?.get(idx)} /> | ||
| </div> | ||
| </Fragment> | ||
| ))} | ||
| </> | ||
| ) : ( | ||
| <div className="code-content p-6"> | ||
| {tokens.map((line, idx) => ( | ||
| <CodeLine key={idx} tokens={line} twoslash={twoslashed?.get(idx)} /> | ||
| ))} | ||
| </div> | ||
| )} |
There was a problem hiding this comment.
The removal of the 'overflow-x-auto' class from the code content wrapper means long code lines won't have horizontal scrolling in the default (non-wrapped) state. The grid layout for line numbers combined with no overflow handling could cause long lines to be cut off or overflow incorrectly. Add 'overflow-x-auto' to the pre element or code-content divs to ensure horizontal scrolling works when word wrap is disabled.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/docs/features/ui/CodeBlock/CodeBlock.client.tsx (1)
118-157: Wrap toggle behavior is solid; consider a couple of small accessibility tweaksThe imperative toggle via
closest('.shiki')anddata-wrappedis a reasonable approach here and matches the new CSS hook, so the core behavior looks good.Two small improvements to consider:
Expose toggle state to assistive tech
Since this button behaves as an on/off toggle, you could add an explicit pressed state:<button onClick={toggleWrap} aria-pressed={isWrapped} type="button" className={cn('border rounded-md p-1', 'hover:bg-selection transition')} aria-label={isWrapped ? 'Disable word wrap' : 'Enable word wrap'} >
type="button"also future-proofs against accidental form submission if this control ever ends up inside a<form>.Keyboard accessibility for hidden controls
WithclassName="hidden group-hover:flex ...", keyboard users can’t tab to the controls unless the container is physically hovered with a pointer. Consider additionally showing them when the code block (or controls) are focused, e.g. via Tailwind’s focus-within variant:<div ref={wrapperRef} className="hidden group-hover:flex group-focus-within:flex absolute top-2 right-2 gap-1" >This keeps the hover affordance while making the controls discoverable via keyboard focus as well.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
apps/docs/features/ui/CodeBlock/CodeBlock.client.tsx(2 hunks)apps/docs/features/ui/CodeBlock/CodeBlock.tsx(3 hunks)apps/docs/styles/main.scss(1 hunks)
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2025-12-11T02:40:11.135Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-ui.mdc:0-0
Timestamp: 2025-12-11T02:40:11.135Z
Learning: Applies to apps/studio/**/*.{ts,tsx} : Use _Shadcn_ form primitives (Form_Shadcn_, FormField_Shadcn_, FormControl_Shadcn_) and prefer FormItemLayout with layout='flex-row-reverse' for form controls
Applied to files:
apps/docs/features/ui/CodeBlock/CodeBlock.tsx
📚 Learning: 2025-12-11T02:40:11.135Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-ui.mdc:0-0
Timestamp: 2025-12-11T02:40:11.135Z
Learning: Applies to apps/studio/**/*.{ts,tsx} : UI components from packages/ui should be imported with _Shadcn_ suffix where applicable (e.g., Input_Shadcn_)
Applied to files:
apps/docs/features/ui/CodeBlock/CodeBlock.tsx
📚 Learning: 2025-12-11T02:40:11.135Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-ui.mdc:0-0
Timestamp: 2025-12-11T02:40:11.135Z
Learning: Read packages/ui/index.tsx file for full list of available components before composing interfaces
Applied to files:
apps/docs/features/ui/CodeBlock/CodeBlock.tsx
📚 Learning: 2025-12-11T02:40:11.135Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-ui.mdc:0-0
Timestamp: 2025-12-11T02:40:11.135Z
Learning: Applies to apps/studio/**/*.{ts,tsx} : Prefer _Shadcn_ components over non-suffixed variants when available
Applied to files:
apps/docs/features/ui/CodeBlock/CodeBlock.tsx
📚 Learning: 2025-12-11T02:40:11.135Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-ui.mdc:0-0
Timestamp: 2025-12-11T02:40:11.135Z
Learning: Applies to apps/studio/**/*.{ts,tsx} : Build forms with react-hook-form + zod
Applied to files:
apps/docs/features/ui/CodeBlock/CodeBlock.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Agent
- GitHub Check: CodeQL analysis (javascript-typescript)
🔇 Additional comments (4)
apps/docs/styles/main.scss (1)
394-399: Word-wrap CSS is correctly scoped and matches the toggle behaviorThe selector and properties line up with the
data-wrappedtoggle fromCodeBlockControlsand should enable wrapping only when explicitly requested, without impacting the default (unwrapped) state. Looks good.apps/docs/features/ui/CodeBlock/CodeBlock.client.tsx (1)
3-4: Imports updated consistently with new controlsThe additional icon and hook imports, plus wiring to local utilities, align with the new
CodeBlockControlsusage and look consistent with the rest of the file. No concerns here.Also applies to: 8-8
apps/docs/features/ui/CodeBlock/CodeBlock.tsx (2)
1-1: Grid layout and controls integration for code blocks look correctThe move to a two-column grid for
lineNumberswith per-line rows (number +.code-content) is a clean way to keep numbers aligned with wrapped lines. The sharedmin-h-5/leading-5and per-line padding for first/last rows should preserve consistent vertical rhythm, and the non-line-number path still routes everything through a single.code-contentcontainer so the wrap CSS applies uniformly.Placing
<CodeBlockControls>inside the.shiki group relativewrapper also matches thegroup-hoverbehavior defined in the client component. Overall, this structure looks sound.Also applies to: 6-6, 75-111
130-147:CodeLinecontainer change tomin-h-5supports wrapping without breaking layoutSwitching the line wrapper to
className="block min-h-5 leading-5"gives each logical line a consistent minimum height while still allowing wrapped content to grow vertically. This pairs well with the grid row layout and should avoid clipping or misalignment when long lines wrap.
ChrisChinchilla
left a comment
There was a problem hiding this comment.
We may find a few bugs along the way, but it looks good so let's ship it. Thanks @Priyanshuthapliyal2005
Thank you so much! Looking forward to work on many more PRs ahead. |
#39689) * feat(code-block): add word wrap functionality and controls to code blocks * feat(code-block): enhance layout of code block with improved line number display and structure * fix h-full issue * fix Prettier issue --------- Co-authored-by: Chris Chinchilla <chris.ward@supabase.io>
* wip * wip * single page * new sections and polishing up * reponsive * nits * semantic titles * optimize imgs * nits * wup * hero bubbles * Update apps/www/components/Wrapped/Pages/SupabaseSelect.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix: Use `amaro` for stripping types in code samples (#41229) * Fix the error for babel/preset-typescript in docs. * Unfix the version. * Try using amaro for type stripping. * Run prettier after stripping types. * Fix tests. --------- Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com> * fix: Fix minor issue in the foreign key selector (#41235) Change the isPending state to isLoading. * docs: Remove empty troubleshooting fields (#41236) * Remove emoty fields * Fix lock file * chore: update self-hosted image versions (#41234) * Feature: show index advisor in table editor (#41166) * added table advisor query * updated to include table editor performance * updated JSON B * added side panel * updated query indexes to show highlights context * show index advisor in table editor * updated invalidation logic * added color updates * added query indexes * updated query performance type * updated overflow and title * put behind flag * remove gap * added on close * Update apps/studio/data/database/table-index-advisor-query.ts Co-authored-by: Charis <26616127+charislam@users.noreply.github.com> * updated styling --------- Co-authored-by: Charis <26616127+charislam@users.noreply.github.com> * fix: useFlag to update initial check of flag store (#41209) * fix flag lib * updated uneeded logic * updated logic * remove line * updated comment * fix: Hide favourites and share snippets on self-hosted variant (#41227) * Hide favorite and share actions for self-hosted version. * Rename the query on save only on platform. * Simplify useCheckOpenAiKeyQuery. * Rename with AI now depends if the OPENAI_API_KEY is set. * Minor fixes. * Fix the tests to use .skip for skipping tests. Remove extra port params. * Make the test for favourites work only on platform variant. * feat(reports): support new database report granularity FE-2221 (#41228) * handle new granularity * undo unnecessary type change * rm console log * fix: blog auto scroll post app router migration for blog (#41220) Enhance TOC highlighting and anchor scroll in blog posts Refactored useActiveAnchors hook to support smooth hash scrolling and improved TOC highlighting based on scroll position. Added options for custom selectors and offset, and updated BlogPostClient to enable scroll-to-anchor and TOC highlight functionality. * fix: remove flakiness with launch options and default timeouts (#41245) * attempt to make table editor tests less flaky * updated race conditions for table editor * updated playwright config with optimized launch options * reduce workers * updated timeouts for tests * updated config to have a global timeout of 20 seconds * updated to be visible * chore: update changelog and image versions file (#41244) * feat(design-system): improve table docs (#41215) * docs updates * docs expansion * minor docs fix * improvements * fix dependencies * docs expansion * more table examples * map over data * improve copy * Update apps/design-system/registry/default/example/table-row-link-actions.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update apps/design-system/registry/default/example/table-row-link-actions.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fixes * fix --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * chore(studio): improve table presentation (#41217) * billing improvements * wrapper improvements * border fix * Nit adjustments * fixes * fix aria * fix loading * fixes * fix --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com> * Save opened side bar in local storage, and init on new session (#41224) * Save opened side bar in local storage, and init on new session * Fix test * Fix * Nit * docs(design-system): Data Table and Data Grid documentation (#41252) * basic differentiation * docs * data-grid examples * data-grid-demo * data-table * demo * use existing components * improvements * markup * docs * remove data table * lint * Update apps/design-system/content/docs/ui-patterns/empty-states.mdx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix ref * use TanStack sorting * grammar * dependency * 📝 Add docstrings to `dnywh/docs/data-table-data-grid` (#41255) Docstrings generation was requested by @MildTomato. * #41252 (comment) The following files were modified: * `apps/design-system/registry/default/example/data-grid-demo.tsx` * `apps/design-system/registry/default/example/data-grid-empty-state.tsx` * `apps/design-system/registry/default/example/data-table-demo.tsx` Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * docs: fix grammatical error in generate-text-embeddings guide (#41187) * docs: fix grammatical error in generate-text-embeddings guide * Update generate-text-embeddings.mdx Co-authored-by: Chris Chinchilla <chris@chrischinchilla.com> --------- Co-authored-by: Chris Chinchilla <chris@chrischinchilla.com> * chore: uniform card and panel padding-x (#41237) * docs: Fix typo in API introduction documentation (#41251) * chore(billing): regenerate api-types to include vanity subdomain entitlement (#41257) chore(billing: regenerate api-types to include vanity subdomain entitlement * Add liam to humans.txt (#41169) * docs: Add link to restoring backup to new Supabase project (#39108) Co-authored-by: Chris Chinchilla <chris.ward@supabase.io> * feat(code-block): add word wrap functionality and controls to code bl… (#39689) * feat(code-block): add word wrap functionality and controls to code blocks * feat(code-block): enhance layout of code block with improved line number display and structure * fix h-full issue * fix Prettier issue --------- Co-authored-by: Chris Chinchilla <chris.ward@supabase.io> * wip * wip * single page * optimize imgs * revert * pkg * update new content * rm overflow * new data * nits * nits * og * border * fix: improve AnimatedCounter and FloatingStatBubbles/Intro components - Update AnimatedCounter to correctly reflect value changes in the DOM. - Add lifetime management for timers in FloatingStatBubbles and FloatingBoxes to prevent memory leaks. - Ensure cleanup of timers on component unmount for better resource management. * dbs * minify images * text-brand-link on light mode * fix grid * max-width on images * address comments * fixes * faster image rotation * upd og * new launch * nitsgs * last nits --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com> Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com> Co-authored-by: Chris Chinchilla <chris.ward@supabase.io> Co-authored-by: Andrey A. <56412611+aantti@users.noreply.github.com> Co-authored-by: Ali Waseem <waseema393@gmail.com> Co-authored-by: Jordi Enric <37541088+jordienr@users.noreply.github.com> Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com> Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com> Co-authored-by: Joshen Lim <joshenlimek@gmail.com> Co-authored-by: Dinesh Dawonauth <dineshddawo@gmail.com> Co-authored-by: Chris Chinchilla <chris@chrischinchilla.com> Co-authored-by: Francesco Sansalvadore <f.sansalvadore@gmail.com> Co-authored-by: 李子衿 <160584929+hhhez@users.noreply.github.com> Co-authored-by: Kanishk Dudeja <kanishk@kanishkdudeja.com> Co-authored-by: lch-supa <liam.hogan@supabase.io> Co-authored-by: Timothy Lim <tim.lim@supabase.io> Co-authored-by: Priyanshu Thapliyal <114170980+Priyanshuthapliyal2005@users.noreply.github.com>








I have read the CONTRIBUTING.md file.
YES
What kind of change does this PR introduce?
feature added
What is the current behavior?
#39421
the terminal or code snippet sections often contain long commands and outputs that require horizontal scrolling
What is the new behavior?
Adds a word wrap button to code blocks. Users can toggle line wrapping for easier reading of long commands; both wrap and copy buttons show on hover.
Additional context
BEFORE
AFTER
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.