From 039db225fd420de37847e3cb5c0dbf65e87e6e9e Mon Sep 17 00:00:00 2001 From: Amanuel Sisay Date: Fri, 30 Jan 2026 14:57:14 +0100 Subject: [PATCH 1/3] Revert "revert: "chore: Vendor react-keyed-flatten-children dependency (#3997)" (#4215)" This reverts commit 0132da6fdb518c009734495f7866f9f8f0778bae. --- THIRD-PARTY-LICENSES | 35 +++++++++++++++++++ package-lock.json | 28 +++++++-------- package.json | 3 +- pages/flashbar/runtime-content.page.tsx | 6 ++-- .../flexible-column-layout/index.tsx | 2 +- src/column-layout/grid-column-layout.tsx | 2 +- src/grid/internal.tsx | 2 +- .../react-keyed-flatten-children/index.ts | 31 ++++++++++++++++ src/space-between/internal.tsx | 6 ++-- 9 files changed, 89 insertions(+), 26 deletions(-) create mode 100644 src/internal/vendor/react-keyed-flatten-children/index.ts diff --git a/THIRD-PARTY-LICENSES b/THIRD-PARTY-LICENSES index 5bfc45cee7..48f408bc43 100644 --- a/THIRD-PARTY-LICENSES +++ b/THIRD-PARTY-LICENSES @@ -277,3 +277,38 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--- + +Name: react-keyed-flatten-children +Version: 3.2.0 +License: MIT +Private: false +Description: Flattens React children and fragments to an array with predictable and stable keys +Repository: git+https://github.com/grrowl/react-keyed-flatten-children.git +Homepage: https://github.com/grrowl/react-keyed-flatten-children +Author: Tom McKenzie +License Copyright: +=== + +MIT License + +Copyright (c) 2019 Tom McKenzie + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/package-lock.json b/package-lock.json index 380c4b26b7..8f889fab23 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "date-fns": "^2.25.0", "intl-messageformat": "^10.3.1", "mnth": "^2.0.0", - "react-keyed-flatten-children": "^2.2.1", + "react-is": ">=16.8.0", "react-transition-group": "^4.4.2", "tslib": "^2.4.0", "weekstart": "^1.1.0" @@ -52,6 +52,7 @@ "@types/node": "^20.17.14", "@types/react": "^16.14.20", "@types/react-dom": "^16.9.14", + "@types/react-is": "^19.2.0", "@types/react-router": "^5.1.18", "@types/react-router-dom": "^5.3.2", "@types/react-test-renderer": "^16.9.12", @@ -4590,6 +4591,16 @@ "@types/react": "^16" } }, + "node_modules/@types/react-is": { + "version": "19.2.0", + "resolved": "https://registry.npmjs.org/@types/react-is/-/react-is-19.2.0.tgz", + "integrity": "sha512-NP2xtcjZfORsOa4g2JwdseyEnF+wUCx25fTdG/J/HIY6yKga6+NozRBg2xR2gyh7kKYyd6DXndbq0YbQuTJ7Ew==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/react": "*" + } + }, "node_modules/@types/react-router": { "version": "5.1.20", "dev": true, @@ -17371,21 +17382,6 @@ }, "node_modules/react-is": { "version": "17.0.2", - "dev": true, - "license": "MIT" - }, - "node_modules/react-keyed-flatten-children": { - "version": "2.2.1", - "license": "MIT", - "dependencies": { - "react-is": "^18.2.0" - }, - "peerDependencies": { - "react": ">=15.0.0" - } - }, - "node_modules/react-keyed-flatten-children/node_modules/react-is": { - "version": "18.3.1", "license": "MIT" }, "node_modules/react-router": { diff --git a/package.json b/package.json index 336ecde7f4..8086c1c731 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "date-fns": "^2.25.0", "intl-messageformat": "^10.3.1", "mnth": "^2.0.0", - "react-keyed-flatten-children": "^2.2.1", + "react-is": ">=16.8.0", "react-transition-group": "^4.4.2", "tslib": "^2.4.0", "weekstart": "^1.1.0" @@ -75,6 +75,7 @@ "@types/node": "^20.17.14", "@types/react": "^16.14.20", "@types/react-dom": "^16.9.14", + "@types/react-is": "^19.2.0", "@types/react-router": "^5.1.18", "@types/react-router-dom": "^5.3.2", "@types/react-test-renderer": "^16.9.12", diff --git a/pages/flashbar/runtime-content.page.tsx b/pages/flashbar/runtime-content.page.tsx index d25d1e8e80..85497f2781 100644 --- a/pages/flashbar/runtime-content.page.tsx +++ b/pages/flashbar/runtime-content.page.tsx @@ -1,8 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import React, { ReactNode, useContext, useState } from 'react'; -import flattenChildren from 'react-keyed-flatten-children'; +import React, { isValidElement, ReactNode, useContext, useState } from 'react'; import { Box, @@ -16,6 +15,7 @@ import { SpaceBetween, } from '~components'; import awsuiPlugins from '~components/internal/plugins'; +import flattenChildren from '~components/internal/vendor/react-keyed-flatten-children'; import { mount, unmount } from '~mount'; import AppContext, { AppContextType } from '../app/app-context'; @@ -27,7 +27,7 @@ type PageContext = React.Context< const nodeAsString = (node: ReactNode) => flattenChildren(node) - .map(node => (typeof node === 'object' ? node.props.children : node)) + .map(node => (isValidElement(node) ? node.props.children : node)) .filter(node => typeof node === 'string') .join(''); diff --git a/src/column-layout/flexible-column-layout/index.tsx b/src/column-layout/flexible-column-layout/index.tsx index c80c38f2d0..f2ca4fa174 100644 --- a/src/column-layout/flexible-column-layout/index.tsx +++ b/src/column-layout/flexible-column-layout/index.tsx @@ -1,11 +1,11 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import React from 'react'; -import flattenChildren from 'react-keyed-flatten-children'; import clsx from 'clsx'; import { useContainerQuery } from '@cloudscape-design/component-toolkit'; +import flattenChildren from '../../internal/vendor/react-keyed-flatten-children'; import { InternalColumnLayoutProps } from '../interfaces'; import styles from './styles.css.js'; diff --git a/src/column-layout/grid-column-layout.tsx b/src/column-layout/grid-column-layout.tsx index 067c725df8..3cf9bbb976 100644 --- a/src/column-layout/grid-column-layout.tsx +++ b/src/column-layout/grid-column-layout.tsx @@ -1,12 +1,12 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import React from 'react'; -import flattenChildren from 'react-keyed-flatten-children'; import clsx from 'clsx'; import { GridProps } from '../grid/interfaces'; import InternalGrid from '../grid/internal'; import { useContainerBreakpoints } from '../internal/hooks/container-queries'; +import flattenChildren from '../internal/vendor/react-keyed-flatten-children'; import { InternalColumnLayoutProps } from './interfaces'; import { COLUMN_TRIGGERS, ColumnLayoutBreakpoint } from './internal'; import { repeat } from './util'; diff --git a/src/grid/internal.tsx b/src/grid/internal.tsx index cc7c05881c..6ea3849735 100644 --- a/src/grid/internal.tsx +++ b/src/grid/internal.tsx @@ -1,7 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import React from 'react'; -import flattenChildren from 'react-keyed-flatten-children'; import clsx, { ClassValue } from 'clsx'; import { useMergeRefs, warnOnce } from '@cloudscape-design/component-toolkit/internal'; @@ -11,6 +10,7 @@ import { Breakpoint, matchBreakpointMapping } from '../internal/breakpoints'; import { useContainerBreakpoints } from '../internal/hooks/container-queries'; import { InternalBaseComponentProps } from '../internal/hooks/use-base-component'; import { isDevelopment } from '../internal/is-development'; +import flattenChildren from '../internal/vendor/react-keyed-flatten-children'; import { GridProps } from './interfaces'; import styles from './styles.css.js'; diff --git a/src/internal/vendor/react-keyed-flatten-children/index.ts b/src/internal/vendor/react-keyed-flatten-children/index.ts new file mode 100644 index 0000000000..bf15e072dd --- /dev/null +++ b/src/internal/vendor/react-keyed-flatten-children/index.ts @@ -0,0 +1,31 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +// Vendored from react-keyed-flatten-children@3.2.0 (MIT License) +// Original source: https://github.com/grrowl/react-keyed-flatten-children + +import { Children, cloneElement, isValidElement, ReactElement, ReactNode } from 'react'; +import { isFragment } from 'react-is'; + +/* Returns React children into an array, flattening fragments. */ + +function isFragmentWithChildren(node: unknown): node is ReactElement<{ children: ReactNode }> { + return isFragment(node); +} + +export default function flattenChildren(children: ReactNode, depth = 0, keys: (string | number)[] = []): ReactNode[] { + return Children.toArray(children).reduce((acc: ReactNode[], node, nodeIndex) => { + if (isFragmentWithChildren(node)) { + acc.push(...flattenChildren(node.props.children, depth + 1, keys.concat(node.key || nodeIndex))); + } else if (isValidElement(node)) { + acc.push( + cloneElement(node, { + key: keys.concat(String(node.key)).join('.'), + }) + ); + } else if (typeof node === 'string' || typeof node === 'number') { + acc.push(node); + } + return acc; + }, []); +} diff --git a/src/space-between/internal.tsx b/src/space-between/internal.tsx index f15e362fb2..ea7a4f6037 100644 --- a/src/space-between/internal.tsx +++ b/src/space-between/internal.tsx @@ -1,7 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import React, { forwardRef } from 'react'; -import flattenChildren from 'react-keyed-flatten-children'; +import React, { forwardRef, isValidElement } from 'react'; import clsx from 'clsx'; import { useMergeRefs } from '@cloudscape-design/component-toolkit/internal'; @@ -9,6 +8,7 @@ import { useMergeRefs } from '@cloudscape-design/component-toolkit/internal'; import { getBaseProps } from '../internal/base-component'; import { InternalBaseComponentProps } from '../internal/hooks/use-base-component'; import WithNativeAttributes from '../internal/utils/with-native-attributes'; +import flattenChildren from '../internal/vendor/react-keyed-flatten-children'; import { SpaceBetweenProps } from './interfaces'; import styles from './styles.css.js'; @@ -52,7 +52,7 @@ const InternalSpaceBetween = forwardRef( ref={mergedRef} > {flattenedChildren.map(child => { - const key = typeof child === 'object' ? child.key : undefined; + const key = isValidElement(child) ? child.key : undefined; return (
From a40b8e37c9a5bcb8f90fcc2bf7166db0abed2037 Mon Sep 17 00:00:00 2001 From: Amanuel Sisay Date: Mon, 2 Feb 2026 18:04:25 +0100 Subject: [PATCH 2/3] fix: add the isFragment function inline and compatible with react v19 --- package.json | 1 - .../react-keyed-flatten-children/index.ts | 29 ++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8086c1c731..95b118b646 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,6 @@ "@types/node": "^20.17.14", "@types/react": "^16.14.20", "@types/react-dom": "^16.9.14", - "@types/react-is": "^19.2.0", "@types/react-router": "^5.1.18", "@types/react-router-dom": "^5.3.2", "@types/react-test-renderer": "^16.9.12", diff --git a/src/internal/vendor/react-keyed-flatten-children/index.ts b/src/internal/vendor/react-keyed-flatten-children/index.ts index bf15e072dd..7921fa9b11 100644 --- a/src/internal/vendor/react-keyed-flatten-children/index.ts +++ b/src/internal/vendor/react-keyed-flatten-children/index.ts @@ -5,7 +5,34 @@ // Original source: https://github.com/grrowl/react-keyed-flatten-children import { Children, cloneElement, isValidElement, ReactElement, ReactNode } from 'react'; -import { isFragment } from 'react-is'; + +// React 19 renamed the element symbol to detect version mismatches and prevent subtle bugs from +// inlined JSX. We check both symbols to support React <19 (legacy) and >=19 (transitional). +// The name "transitional" indicates this will change again in future versions. +// Reference: https://github.com/facebook/react/pull/28813 +const REACT_LEGACY_ELEMENT_TYPE: symbol = Symbol.for('react.element'); +const REACT_ELEMENT_TYPE: symbol = Symbol.for('react.transitional.element'); + +const REACT_FRAGMENT_TYPE: symbol = Symbol.for('react.fragment'); + +// Simplified version of react-is typeOf that checks for fragment types only +// Reference: https://github.com/facebook/react/blob/main/packages/react-is/src/ReactIs.js#L40 +function typeOfFragment(object: any): symbol | undefined { + if (typeof object === 'object' && object !== null) { + const $$typeof = object.$$typeof; + if ($$typeof === REACT_ELEMENT_TYPE || $$typeof === REACT_LEGACY_ELEMENT_TYPE) { + const type = object.type; + if (type === REACT_FRAGMENT_TYPE) { + return type; + } + } + } + return undefined; +} + +function isFragment(object: any): boolean { + return typeOfFragment(object) === REACT_FRAGMENT_TYPE; +} /* Returns React children into an array, flattening fragments. */ From 50f72caa59ec3fb5cebeed21533ada64b1924e32 Mon Sep 17 00:00:00 2001 From: Amanuel Sisay Date: Mon, 2 Feb 2026 18:19:04 +0100 Subject: [PATCH 3/3] feat: Add BigInt support for React 19 --- .../vendor/react-keyed-flatten-children/index.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/internal/vendor/react-keyed-flatten-children/index.ts b/src/internal/vendor/react-keyed-flatten-children/index.ts index 7921fa9b11..38774dc398 100644 --- a/src/internal/vendor/react-keyed-flatten-children/index.ts +++ b/src/internal/vendor/react-keyed-flatten-children/index.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Vendored from react-keyed-flatten-children@3.2.0 (MIT License) -// Original source: https://github.com/grrowl/react-keyed-flatten-children +// Original source: https://github.com/grrowl/react-keyed-flatten-children/tree/120a286144c7fdc76b64daadaeae0df7d255b497 import { Children, cloneElement, isValidElement, ReactElement, ReactNode } from 'react'; @@ -40,7 +40,11 @@ function isFragmentWithChildren(node: unknown): node is ReactElement<{ children: return isFragment(node); } -export default function flattenChildren(children: ReactNode, depth = 0, keys: (string | number)[] = []): ReactNode[] { +export default function flattenChildren( + children: ReactNode, + depth: number = 0, + keys: (string | number)[] = [] +): ReactNode[] { return Children.toArray(children).reduce((acc: ReactNode[], node, nodeIndex) => { if (isFragmentWithChildren(node)) { acc.push(...flattenChildren(node.props.children, depth + 1, keys.concat(node.key || nodeIndex))); @@ -50,7 +54,7 @@ export default function flattenChildren(children: ReactNode, depth = 0, keys: (s key: keys.concat(String(node.key)).join('.'), }) ); - } else if (typeof node === 'string' || typeof node === 'number') { + } else if (typeof node === 'string' || typeof node === 'number' || typeof node === 'bigint') { acc.push(node); } return acc;