-
Notifications
You must be signed in to change notification settings - Fork 509
fix(vue3): provide keys for components, that could be reused #15401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Maksim Sukharev <[email protected]>
| <template v-else-if="submenu === 'notifications'"> | ||
| <NcActionButton :aria-label="t('spreed', 'Back')" | ||
| <NcActionButton | ||
| key="action-back" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this refresh good enough even when its reused inside a parent that has a different key? Just asking for my understanding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if parent has a different key, it should re-render parent and everything underneath
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this refresh good enough even when its reused inside a parent that has a different key? Just asking for my understanding
Key doesn't trigger re-rendring, but re-order/re-mount.
And Vue doesn't support parent remounting without children remounting.
So changing the parent key completely destroys and re-creates children. Not just re-render.
DorraJaouad
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nearest parent is NcListItem (skipping templates) and it has key updated by token so it should be enough?
It's not about Virtual scroller, but switching submenus (see above) |
ShGKme
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- passing
keyforces component to rerender (if submenu page was changed)
Rerendering is triggered by reactive data change.
If a component doesn't rerender on a state change, there is a reactivity loss, and it should be fixed.
key either help Vue to identify an instance and reorder instances instead of updating props of instances (v-for case), or triggers remount (recreate) of a component instance in case of a completely new key.
NcActionButton supports updating props even in a v-for without key.
But probably something goes wrong due to our manual rendering in NcActions.
These keys don't hurt (they don't create unneeded remounts), let's go with them.
☑️ Resolves
keyforces component to rerender (if submenu page was changed)close-after-clickcould be leaked astrueto a new component, which should not have it🖌️ UI Checklist
🚧 Tasks
🏁 Checklist