Skip to content

mantine-ui: stable AND definitely unique key for /alerts cards#16044

Merged
juliusv merged 4 commits intoprometheus:mainfrom
amanycodes:fix/stable-cardUI-key
Apr 24, 2025
Merged

mantine-ui: stable AND definitely unique key for /alerts cards#16044
juliusv merged 4 commits intoprometheus:mainfrom
amanycodes:fix/stable-cardUI-key

Conversation

@amanycodes
Copy link
Contributor

Replaced the index i with g.name-g.file which I think is stable (and unique) enough, I haven't caught any edge cases yet, but was also wondering maybe generate some unique ID (hash, uuid) and assign them. but re-renders when a card is removed might cause some issues. 🤔

@amanycodes amanycodes requested a review from juliusv as a code owner February 15, 2025 14:01
@rexagod
Copy link
Contributor

rexagod commented Feb 16, 2025

I'm not sure why is the current i doesn't work here as is? Is there an issue this can be linked to for more context, or could you explain a bit on any unexpected behaviors that stemmed from this?

@amanycodes
Copy link
Contributor Author

Right now the key i is coming from the array index in the map, which is unstable because if one card in the middle isn’t rendered or is removed, the indexes of all following cards shift; for example, a card that used to have index i+1 will now have index i, leading to duplicate keys. This can cause issues such as React mixing up component states (since it relies on keys), mounting issues, and UI bugs.
It's safe to have a stable AND definitely unique key.

@amanycodes amanycodes requested a review from juliusv February 21, 2025 04:43
@amanycodes
Copy link
Contributor Author

I wrote stable AND definitely unique keys for the /rules page as well.

@krajorama
Copy link
Member

Hello from the bug scrub, PR seems active, leaving open.

Signed-off-by: amanycodes <amanycodes@gmail.com>
Signed-off-by: amanycodes <amanycodes@gmail.com>
Signed-off-by: amanycodes <amanycodes@gmail.com>
Signed-off-by: amanycodes <amanycodes@gmail.com>
@amanycodes amanycodes force-pushed the fix/stable-cardUI-key branch from 11baddb to ad84642 Compare April 24, 2025 14:39
@amanycodes
Copy link
Contributor Author

@juliusv I have rebased this one aswell. Please review the changes!

Copy link
Member

@juliusv juliusv left a comment

Choose a reason for hiding this comment

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

👍 Thanks!

@juliusv juliusv enabled auto-merge April 24, 2025 15:34
@juliusv juliusv merged commit 9ab60c5 into prometheus:main Apr 24, 2025
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants