From 6eab2c025c2665eb2120b71a2361183a6f583248 Mon Sep 17 00:00:00 2001 From: Trevor Burnham Date: Sat, 24 Jan 2026 19:06:36 -0500 Subject: [PATCH] refactor: minor cleanups - Hoist regionProps objects to module-level constants to avoid recreation on every render - Remove redundant optional chaining in highlight/index.tsx where token.className is already checked in the ternary condition --- src/code-view/highlight/index.tsx | 2 +- src/code-view/internal.tsx | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/code-view/highlight/index.tsx b/src/code-view/highlight/index.tsx index d37f53d..d0103e8 100644 --- a/src/code-view/highlight/index.tsx +++ b/src/code-view/highlight/index.tsx @@ -18,7 +18,7 @@ export function createHighlight(rules: Ace.HighlightRules): CreateHighlightType {lineTokens.map((token, tokenIndex) => { return token.className ? ( - + {token.value} ) : ( diff --git a/src/code-view/internal.tsx b/src/code-view/internal.tsx index 978f69f..59a6aec 100644 --- a/src/code-view/internal.tsx +++ b/src/code-view/internal.tsx @@ -13,6 +13,10 @@ import styles from "./styles.css.js"; const ACE_CLASSES = { light: "ace-cloud_editor", dark: "ace-cloud_editor_dark" }; +// Static props objects to avoid recreation on every render. +const REGION_PROPS = { role: "region" } as const; +const NO_REGION_PROPS = {} as const; + type InternalCodeViewProps = CodeViewProps & InternalBaseComponentProps; // Breaks down the input code for non-highlighted code-view into React @@ -47,7 +51,7 @@ export function InternalCodeView({ const containerRef = useRef(null); const darkMode = useCurrentMode(containerRef) === "dark"; - const regionProps = ariaLabel || ariaLabelledby ? { role: "region" } : {}; + const regionProps = ariaLabel || ariaLabelledby ? REGION_PROPS : NO_REGION_PROPS; const accessibleLineNumbers = lineNumbers && i18nStrings?.lineNumberLabel && i18nStrings?.codeLabel; // Create tokenized React nodes of the content.