Skip to content

having a child slot causes parent to render unnecessarily when the parent is being used in a scoped slot #10512

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
matthewma7 opened this issue Sep 12, 2019 · 2 comments

Comments

@matthewma7
Copy link

matthewma7 commented Sep 12, 2019

Version

2.6.10

Reproduction link

https://jsfiddle.net/jfmorio/okvza9fu/8/

Steps to reproduce

Click on the ‘+1’ button

What is expected?

The render() function inside the component 'consumer' won't be called

What is actually happening?

the render function is called


If there is no grandchild slot, the render() won't be called.
https://jsfiddle.net/jfmorio/okvza9fu/10/

If it is not a scoped slot, it works as expected.
https://jsfiddle.net/jfmorio/okvza9fu/11/

If it an old syntax named slot. It works as expected.
https://jsfiddle.net/jfmorio/okvza9fu/13/
However, if the old syntax provides a slot scope. It will cause rendering.
https://jsfiddle.net/jfmorio/okvza9fu/22/
So basically, a scoped slot will cause the component to render when the component has a slot child. Even though neither the component or the slot child is using the variable within render.

@posva
Copy link
Member

posva commented Sep 13, 2019

The new syntax makes it a scoped slot so it also used to render with the old syntax

<wrapper>
    <template slot="content" slot-scope="data">
      <consumer >
        <div>having this slot caused this problem</div>
      </consumer>
      </template>
  </wrapper>

That's why it needs to render the slot when wrapper renders, because the slot is rendered as part of wrapper since it passes data and when anything on the template changes, the whole template re renders. For a regular slot, the render happens when the root renders: https://jsfiddle.net/d1x2m0ck/ click the button with a number to see the alert

For slots to render only when things changes, we will need to change how slots are rendered. See #6351

@posva posva closed this as completed Sep 13, 2019
@matthewma7
Copy link
Author

Thank you for answering my question. 🙂
The behavior makes sense now but still undesired.

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

2 participants