Skip to content
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

Using v-if with v-slot directive cause unnecessary update hook #6833

Open
nndnha opened this issue Oct 7, 2022 · 4 comments
Open

Using v-if with v-slot directive cause unnecessary update hook #6833

nndnha opened this issue Oct 7, 2022 · 4 comments
Labels
🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. need guidance The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further. scope: compiler scope: slots

Comments

@liulinboyi
Copy link
Member

Because it's DYNAMIC_SLOTS, the function shouldUpdateComponent will return true, the component will update and the lifecycle onUpdated will trigger.

if (patchFlag & PatchFlags.DYNAMIC_SLOTS) {
// slot content that references values that might have changed,
// e.g. in a v-for
return true
}

image

@posva posva added need guidance The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further. scope: slots scope: compiler 🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. labels Oct 8, 2022
@nndnha
Copy link
Author

nndnha commented Oct 13, 2022

@SuzumiyaHaku v-if="true" doesn't make sense in any real apps, I used it just to make a short description of the problem and the real problem is something like this

@SuzumiyaHaku
Copy link

I think you need the v-memo directive.

<template>
  <h1>{{ counter }}</h1>
  <Comp  v-memo="[showHeader]">
    <template v-if="showHeader" #header>
      Header here
    </template>
  </Comp>
</template>

@nndnha
Copy link
Author

nndnha commented Oct 14, 2022

@SuzumiyaHaku Thanks for your v-memo suggestion! There is another way to solve this:

<template>
  <h1>{{ counter }}</h1>
  <Comp>
    <template #header>
      <template v-if="showHeader">
         Header here
      </template> 
    </template>
  </Comp>
</template>

The main point of this issue is that I think the combination of v-if and v-slot in this case surely is a performance pitfall so we either fix it, or we should at least mention it to the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. need guidance The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further. scope: compiler scope: slots
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants