Skip to content

Content in default slot causes component to re-render when the parent re-renders #8342

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

Closed
JosephSilber opened this issue Jun 12, 2018 · 2 comments

Comments

@JosephSilber
Copy link

JosephSilber commented Jun 12, 2018

Version

2.5.16

Reproduction link

https://codepen.io/JosephSilber/pen/KeWjzr

Description

Passing content in a slot causes the component to re-render when the parent re-renders, even if the component's data hasn't changed.

Steps to reproduce

  1. Create a simple component that shows the amount of times it's been rendered:

    Vue.component('times-rendered', {
        created() {
          this.timesRendered = 0
        },
        render(h) {        
          return h('div', `Times rendered: ${++this.timesRendered}`)
        }
    });
  2. Use this component twice. Once with content in the default slot, once without. After the component is mounted, trigger any update to its data:

    <template>
        <div>
          <div>{{ updateTrigger }}</div>
          <times-rendered></times-rendered>
          <times-rendered>
            Any content in the default slot causes a re-render. Why?
          </times-rendered>
        </div>
    </template>
    
    <script>
    export default {
        data: () => ({ updateTrigger: false }),
        
        async mounted() {
          await this.$nextTick()
          
          this.updateTrigger = true
        },
    };
    </script>

What is expected?

I would expect each instance of the component to only render once.

What is actually happening?

The component with content in the slot renders twice.


I'm not actually sure whether this is a bug or a feature request. Maybe this is expected behavior currently. If it is, then I guess this would be better classified as a feature request.

@jacekkarczmarczyk
Copy link

Duplicate of #6351?

@posva
Copy link
Member

posva commented Jun 13, 2018

The rerender happens because the whole template renders again because of updateTrigger
Let's mark this as a duplicate of #6351

@posva posva closed this as completed Jun 13, 2018
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

No branches or pull requests

3 participants