feat: CodeBlock + utils - #155
Conversation
ENG-5509 Code Block + Code Group
Move the codeGroup component into the OSS components package repository. Check general rules and specifics in https://www.notion.so/mintlify/Docs-Components-rules-audit-2d1aa841023480ba93b7e1a8676522db |
…thryn/eng-5509-code-block
| }: { | ||
| filename?: string; | ||
| icon?: string; | ||
| codeBlockTheme?: 'dark' | 'system'; | ||
| children?: ReactNode; | ||
| }) { |
There was a problem hiding this comment.
can we move this to CodeHeaderProps
There was a problem hiding this comment.
or just Pick from CodeBlockPropsBase
| code: string; | ||
| // pass in useAnalyticsContext('docs.code_group.copy') | ||
| onCopy?: (result: CopyToClipboardResult, textToCopy?: string) => void; | ||
| codeBlockTheme?: 'system' | 'dark'; |
There was a problem hiding this comment.
we should move this to a global type and re-use for all codeblock components
| onCopied?: (result: CopyToClipboardResult, textToCopy?: string) => void; | ||
| className?: string; | ||
| showTooltip?: boolean; | ||
| codeBlockTheme?: 'system' | 'dark'; |
| isCopiedActive: boolean; | ||
| showTooltip?: boolean; | ||
| className?: string; | ||
| codeBlockTheme?: 'system' | 'dark'; |
| let rafId: number | undefined; | ||
| if (contentRef.current != null && enable) { | ||
| rafId = requestAnimationFrame(() => { | ||
| if (contentRef.current != null) { | ||
| setCalculatedHeight( | ||
| contentRef.current.scrollHeight + | ||
| (numberOfLines && numberOfLines < SMALL_EXPANDABLE_NUMBER_OF_LINES | ||
| ? SMALL_EXPANDED_HEIGHT_OFFSET | ||
| : EXPANDED_HEIGHT_OFFSET) | ||
| ); | ||
| } | ||
| }); | ||
| } |
There was a problem hiding this comment.
lowest priority, but this is hard to read
…thryn/eng-5509-code-block
| "children:!my-0 children:!shadow-none children:!bg-transparent relative h-full w-0 min-w-full max-w-full px-4 py-3.5 text-sm leading-6 dark:bg-codeblock", | ||
| "code-block-background overflow-x-auto transition-[height] duration-300 ease-in-out", | ||
| "**:outline-0 **:ring-0 **:focus:outline-0 **:focus:ring-0", | ||
| props.filename ? "rounded-xt" : "rounded-2xl", |
There was a problem hiding this comment.
you mean the unrounded corners peeking over? 👀
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| const useGetShikiHighlightedHtml = ( | ||
| props: ShikiHighlightedHtmlArgs | ||
| ): string | undefined => { | ||
| const htmlOrPromise = getShikiHighlightedHtml(props); |
There was a problem hiding this comment.
Syntax highlighting runs on every render without memoization
Medium Severity
The useGetShikiHighlightedHtml hook calls getShikiHighlightedHtml(props) synchronously at the top of the hook on every render. In base-code-block.tsx, the props object is created inline without memoization, meaning a new object reference is passed on each render. When the highlighter is ready, the expensive syntax highlighting work runs on every component render rather than only when the code content or options actually change. For large code blocks, this could cause noticeable UI jank and unnecessary CPU usage.
Additional Locations (1)
| const useGetShikiHighlightedHtml = ( | ||
| props: ShikiHighlightedHtmlArgs | ||
| ): string | undefined => { | ||
| const htmlOrPromise = getShikiHighlightedHtml(props); |
There was a problem hiding this comment.
Syntax highlighting runs on every render without memoization
Medium Severity
The useGetShikiHighlightedHtml hook calls getShikiHighlightedHtml(props) synchronously at the top of the hook on every render. In base-code-block.tsx, the props object is created inline without memoization, meaning a new object reference is passed on each render. When the highlighter is ready, the expensive syntax highlighting work runs on every component render rather than only when the code content or options actually change. For large code blocks, this could cause noticeable UI jank and unnecessary CPU usage.

Note
Introduces a production-ready code rendering system and UI.
CodeBlockcomponent (+ header/footer/copy button) with Shiki highlighting, line numbers, focus/highlight, diff markers, wrapping, expandable preview, light/dark and custom theme supportcode.cssandtwoslash.css, custom scrollbar plugin, and theme tokens wired intostyles.cssCodeStyling, SHIKI theme list, icon utilities update; exported via components indexshiki,@shikijs/*,comlink,hast, types)Risk: Medium. New dependencies, worker-based highlighting, and Tailwind plugin/CSS changes may affect build size, styling, and runtime in the components package.
Written by Cursor Bugbot for commit 367bcd7. This will update automatically on new commits. Configure here.