You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have confirmed that this bug has not been reported yet
Description
I'm trying to render multiple divs with a line break between them
(<div>str1</div><br /><div>str2</div><br /><div>str3</div>).
Problem arises when setting dangerouslyDisableWhitespaceCollapsing prop to true, I get the following yellow box warning:
Warning: Encountered two children with the same key, 0. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.
But the problem is, TPhrasing render nodes always have a nodeIndex = 0
Suggested fix:
Use element's index additionally to nodeIndex when assigning keys to children
constkey=`${childTnode.nodeIndex}_${n}`
This ensures that every child always has a unique key
Is this fix acceptable? Should I submit a PR?
React Native Information
System:
OS: Linux 5.4 Linux Mint 20.3 (Una)
CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
Memory: 1.17 GB / 7.69 GB
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 14.9.0 - /usr/local/bin/node
Yarn: Not Found
npm: 6.14.8 - /usr/local/bin/npm
Watchman: 2022.03.21.00 - /home/linuxbrew/.linuxbrew/bin/watchman
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Languages:
Java: Not Found
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.68.1 => 0.68.1
npmGlobalPackages:
*react-native*: Not Found
RNRH Version
6.3.4
Tested Platforms
Android
iOS
Web
MacOS
Windows
Reproduction Platforms
Android
iOS
Web
MacOS
Windows
Minimal, Reproducible Example
Yellow box warnings seem to be disabled on snack, so I've created this git repo.
eVoloshchak
changed the title
Non-unique React keys when using dangerouslyDisableWhitespaceCollapsing
React keys warning when using dangerouslyDisableWhitespaceCollapsing
May 12, 2022
Decision Table
<yyy>
is not rendered”Good Faith Declaration
Description
I'm trying to render multiple divs with a line break between them
(
<div>str1</div><br /><div>str2</div><br /><div>str3</div>
).Problem arises when setting
dangerouslyDisableWhitespaceCollapsing
prop totrue
, I get the following yellow box warning:Root cause:
Library calls mapCollapsibleChildren for each child and assigns a key to it on this line:
But the problem is,

TPhrasing
render nodes always have a nodeIndex = 0Suggested fix:
Use element's index additionally to nodeIndex when assigning keys to children
This ensures that every child always has a unique key

Is this fix acceptable? Should I submit a PR?
React Native Information
RNRH Version
6.3.4
Tested Platforms
Reproduction Platforms
Minimal, Reproducible Example
Yellow box warnings seem to be disabled on snack, so I've created this git repo.
Additional Notes
No response
The text was updated successfully, but these errors were encountered: