From 7d0cb1a5e389fb3e0813ffa291567f2e696cf9a9 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 Children.only() already validates that the highlight result is a single element, so wrapping it in a Fragment first just to read .props.children back off the wrapper is a no-op. Call Children.only() on the result directly and cast, since the highlight prop is typed as ReactNode. --- src/code-view/internal.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/code-view/internal.tsx b/src/code-view/internal.tsx index 48f3e4e..9e0b212 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, useMemo, useRef } from "react"; +import { Children, ReactElement, useMemo, useRef } from "react"; import clsx from "clsx"; import { useCurrentMode } from "@cloudscape-design/component-toolkit/internal"; @@ -56,9 +56,7 @@ export function InternalCodeView({ // Memoize tokenized React nodes to avoid re-running highlight on every render. const code = useMemo(() => (highlight ? highlight(content) : textHighlight(content)), [content, highlight]); - // Create elements from the nodes. - const codeElementWrapper: ReactElement = createElement(Fragment, null, code); - const codeElement = Children.only(codeElementWrapper.props.children); + const codeElement = Children.only(code) as ReactElement; return (