From ae09ddecc4716aa45c2091dca6638dfde88de8e0 Mon Sep 17 00:00:00 2001 From: Trevor Burnham Date: Sat, 24 Jan 2026 18:52:49 -0500 Subject: [PATCH] refactor: remove unnecessary Fragment wrapping The highlight functions already return a ReactElement, so there's no need to wrap it in a Fragment and immediately unwrap it with Children.only(). Cast directly to ReactElement instead. --- src/code-view/internal.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/code-view/internal.tsx b/src/code-view/internal.tsx index 978f69f..a8c51b3 100644 --- a/src/code-view/internal.tsx +++ b/src/code-view/internal.tsx @@ -1,6 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { Children, createElement, Fragment, ReactElement, useRef } from "react"; +import { Children, ReactElement, useRef } from "react"; import clsx from "clsx"; import { useCurrentMode } from "@cloudscape-design/component-toolkit/internal"; @@ -51,10 +51,8 @@ export function InternalCodeView({ const accessibleLineNumbers = lineNumbers && i18nStrings?.lineNumberLabel && i18nStrings?.codeLabel; // Create tokenized React nodes of the content. - const code = highlight ? highlight(content) : textHighlight(content); - // Create elements from the nodes. - const codeElementWrapper: ReactElement = createElement(Fragment, null, code); - const codeElement = Children.only(codeElementWrapper.props.children); + // Both highlight() and textHighlight() return a element containing line children. + const codeElement = (highlight ? highlight(content) : textHighlight(content)) as ReactElement; return (