Skip to content
This repository was archived by the owner on Jun 28, 2026. It is now read-only.

Fix MultiSelect non-unique keys#8050

Merged
melloware merged 1 commit into
primefaces:masterfrom
rubenochiavone:fix/multiselect-non-unique-keys
May 31, 2025
Merged

Fix MultiSelect non-unique keys#8050
melloware merged 1 commit into
primefaces:masterfrom
rubenochiavone:fix/multiselect-non-unique-keys

Conversation

@rubenochiavone

Copy link
Copy Markdown
Contributor

Fixes #8049.

@github-actions

Copy link
Copy Markdown

Thanks a lot for your contribution! But, PR does not seem to be linked to any issues. Please manually link to an issue or mention it in the description using #<issue_id>.

@melloware

Copy link
Copy Markdown
Member

Weird shouldn't this key make it unique since its using index ?

@melloware melloware left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain why this fixes it?

@rubenochiavone

Copy link
Copy Markdown
Contributor Author

Here is the call site of MultiSelectItem in MultiSelectPanel's createItem function:

<MultiSelectItem
hostName={props.hostName}
key={optionKey}
focusedOptionIndex={props.focusedOptionIndex}
label={optionLabel}
option={option}
style={style}
index={index}
template={props.itemTemplate}
selected={selected}
onClick={props.onOptionSelect}
onMouseMove={changeFocusedItemOnHover}
disabled={disabled}
className={props.itemClassName}
checkboxIcon={props.checkboxIcon}
isUnstyled={isUnstyled}
ptm={ptm}
cx={cx}
/>

Although MultiSelectItem returns a key in every render, it's not being used here and is causing this warning. If we remove the key from MultiSelectItem usage (line 172 above), I'd expect MultiSelectItem returned key was being used, but the non-unique warning still happens - which means it wasn't used. So, currently I don't see any reasonable use for keeping it. Technically, the key being return by MultiSelectItem is not wrong, though, I wonder if could be an issue with the react version being used.

Anyway, feel free to close the PR if you think is not worth it.

@rubenochiavone rubenochiavone requested a review from melloware May 31, 2025 15:08
@melloware

Copy link
Copy Markdown
Member

yeah that is why i was confused i wonder if its a false positive React warning?

@melloware melloware merged commit 53e7bcd into primefaces:master May 31, 2025
2 of 3 checks passed
@rubenochiavone rubenochiavone deleted the fix/multiselect-non-unique-keys branch May 31, 2025 15:59
@rubenochiavone

Copy link
Copy Markdown
Contributor Author

yeah that is why i was confused i wonder if its a false positive React warning?

Yeah, probably.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MultiSelect has non-unique key warning

2 participants