Skip to content

feat: CodeBlock + utils - #155

Merged
lawreka merged 22 commits into
mainfrom
kathryn/eng-5509-code-block
Jan 22, 2026
Merged

feat: CodeBlock + utils#155
lawreka merged 22 commits into
mainfrom
kathryn/eng-5509-code-block

Conversation

@lawreka

@lawreka lawreka commented Jan 21, 2026

Copy link
Copy Markdown
Contributor
  • adds everything needed (shiki, etc.) for CodeBlock and CodeBlock stories

Note

Introduces a production-ready code rendering system and UI.

  • New CodeBlock component (+ header/footer/copy button) with Shiki highlighting, line numbers, focus/highlight, diff markers, wrapping, expandable preview, light/dark and custom theme support
  • Shiki integration: transformers, theme/lang mapping, background color extraction, HTML generation hook, and a web worker for large snippets; utilities for code extraction and styling
  • Styling: comprehensive code.css and twoslash.css, custom scrollbar plugin, and theme tokens wired into styles.css
  • Storybook: extensive stories and sample snippets covering themes, focus/highlight, diffs, and expandability
  • New constants/types: CodeStyling, SHIKI theme list, icon utilities update; exported via components index
  • Build/config: Vite worker format enabled; dependencies added (shiki, @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.

@linear

linear Bot commented Jan 21, 2026

Copy link
Copy Markdown
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

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@lawreka
lawreka requested review from dks333 and pqoqubbw January 21, 2026 21:57
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Comment on lines +137 to +142
}: {
filename?: string;
icon?: string;
codeBlockTheme?: 'dark' | 'system';
children?: ReactNode;
}) {

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.

can we move this to CodeHeaderProps

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.

or just Pick from CodeBlockPropsBase

code: string;
// pass in useAnalyticsContext('docs.code_group.copy')
onCopy?: (result: CopyToClipboardResult, textToCopy?: string) => void;
codeBlockTheme?: 'system' | 'dark';

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.

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';

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.

ditto

isCopiedActive: boolean;
showTooltip?: boolean;
className?: string;
codeBlockTheme?: 'system' | 'dark';

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.

ditto

Comment on lines +13 to +25
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)
);
}
});
}

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.

lowest priority, but this is hard to read

cursor[bot]

This comment was marked as outdated.

"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",

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.

we should also fix this in client

Image

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.

rounded-[14px]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you mean the unrounded corners peeking over? 👀

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ah yes will do

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)

Fix in Cursor Fix in Web

const useGetShikiHighlightedHtml = (
props: ShikiHighlightedHtmlArgs
): string | undefined => {
const htmlOrPromise = getShikiHighlightedHtml(props);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)

Fix in Cursor Fix in Web

@lawreka
lawreka merged commit 03ca0b5 into main Jan 22, 2026
3 checks passed
@lawreka
lawreka deleted the kathryn/eng-5509-code-block branch January 22, 2026 21:27
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