diff --git a/src/code-view/internal.tsx b/src/code-view/internal.tsx index 978f69f..f766041 100644 --- a/src/code-view/internal.tsx +++ b/src/code-view/internal.tsx @@ -13,6 +13,13 @@ import styles from "./styles.css.js"; const ACE_CLASSES = { light: "ace-cloud_editor", dark: "ace-cloud_editor_dark" }; +// Static style objects hoisted outside component to avoid recreation on every render. +const COL_STYLE_SHRINK = { width: 1 }; +const COL_STYLE_AUTO = { width: "auto" }; + +// Static class name for line numbers (doesn't depend on props). +const lineNumberClassName = clsx(styles["line-number"], styles.unselectable); + type InternalCodeViewProps = CodeViewProps & InternalBaseComponentProps; // Breaks down the input code for non-highlighted code-view into React @@ -56,6 +63,12 @@ export function InternalCodeView({ const codeElementWrapper: ReactElement = createElement(Fragment, null, code); const codeElement = Children.only(codeElementWrapper.props.children); + // Compute class name for code lines once, outside the render loop. + const codeLineSpanClassName = clsx( + codeElement.props.className, + wrapLines ? styles["code-line-wrap"] : styles["code-line-nowrap"], + ); + return (
- - + + {accessibleLineNumbers && ( @@ -92,10 +105,7 @@ export function InternalCodeView({ return ( {lineNumbers && ( - + {index + 1} @@ -103,14 +113,7 @@ export function InternalCodeView({ )} - - {child} - + {child}