-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Unnecessary renders on parent update when $attrs is bound #10115
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
Comments
This is basically the same problem as with |
Ah yep, missed that one. Looks like we have |
The workaround I'm using for now is to mutate a single object instead: data: () => ({
$_attrs: {},
$_listeners: {},
}),
watch: {
// Work around unwanted re-renders: https://github.com/vuejs/vue/issues/10115
// Make sure to use `v-bind="$data.$_attrs"` instead of `v-bind="$attrs"`
$attrs: {
handler (val) {
for (const attr in val) {
this.$set(this.$data.$_attrs, attr, val[attr])
}
},
immediate: true
},
$listeners: {
handler (val) {
for (const listener in val) {
this.$set(this.$data.$_listeners, listener, val[listener])
}
},
immediate: true
}
}, https://codepen.io/anon/pen/rXpGbj?editors=1010 I 100% guarantee there's bugs in this btw. |
* fix(perf): avoid useless re-render on parent update fixes #6201 see vuejs/vue#7257 and vuejs/vue#10115 * test: disable sync see vuejs/vue-test-utils#1130 * test: disable more sync, skip unfixable tests * Update packages/vuetify/src/mixins/binds-attrs/index.ts Co-Authored-By: John Leider <[email protected]>
Yes, need to delete attrs which wasn't in $attrs any more. |
Consider this scenario: <my-button v-if="visible" />
<my-button v-else detail /> If we toggle There are three ways to help this out:
<my-button v-show="visible" />
<my-button v-show="!visible" detail />
<my-button v-if="visible" key="a" />
<my-button v-else="visible" key="b" detail />
$attrs: {
handler (val) {
const oldKeys = Object.keys(this.$data.$_attrs)
for (const attr in val) {
this.$set(this.$data.$_attrs, attr, val[attr])
const index = oldKeys.indexOf(attr)
if (index > -1) {
oldKeys.splice(index, 1)
}
}
for (const attr of oldKeys) {
this.$delete(this.$data.$_attrs, attr);
}
},
immediate: true
}, |
Version
2.6.10
Reproduction link
https://codepen.io/anon/pen/zQVRgG?editors=1010
Steps to reproduce
Type something into the first field
Uncomment line 8 or 14 then try again
What is expected?
In console:
What is actually happening?
In console:
The text was updated successfully, but these errors were encountered: