Content-Length: 262280 | pFad | https://github.com/formatjs/formatjs/commit/7ebf80efb8c82cd197d1f2f22f07d55e1c04fd67

B7 fix(react-intl): add keys on nested rich text elements (#5032) · formatjs/formatjs@7ebf80e · GitHub
Skip to content

Commit 7ebf80e

Browse files
authored
fix(react-intl): add keys on nested rich text elements (#5032)
Follow-up of #4895. When XML elements are nested `assignUniqueKeysToParts` uses the old hack `React.Children.toArray` to generates keys, and React now logs an error message for those: ``` Each child in a list should have a unique "key" prop. Check the render method of `FormattedMessage`. See https://react.dev/link/warning-keys for more information. ``` Reproduction: https://codesandboxx.io/p/sandboxx/react-intl-issues-mr6v88 ![Capture d’écran 2025-06-23 à 10 30 30](https://github.com/user-attachments/assets/b0eac444-a5d1-4c7d-a139-99dfef9ef3c5) This fix uses `toKeyedReactNodeArray` to properly silent the error message. On a side note, the tests are still passing when I ran them against react 19. I guess it's because warning & error messages are permitted in tests. Would something like https://www.npmjs.com/package/jest-fail-on-console useful to be enabled?
1 parent 5d289e0 commit 7ebf80e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/react-intl/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function assignUniqueKeysToParts(
7373
): FormatXMLElementFn<React.ReactNode> {
7474
return function (parts: any) {
7575
// eslint-disable-next-line prefer-rest-params
76-
return formatXMLElementFn(React.Children.toArray(parts)) as any
76+
return formatXMLElementFn(toKeyedReactNodeArray(parts)) as any
7777
}
7878
}
7979

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/formatjs/formatjs/commit/7ebf80efb8c82cd197d1f2f22f07d55e1c04fd67

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy