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

Lazy component inside UTabs are never lazyloaded #1915

Closed
Tragio opened this issue Jun 25, 2024 · 4 comments
Closed

Lazy component inside UTabs are never lazyloaded #1915

Tragio opened this issue Jun 25, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@Tragio
Copy link
Contributor

Tragio commented Jun 25, 2024

Environment

  • Operating System: Darwin
  • Node Version: v20.10.0
  • Nuxt Version: 3.12.2
  • CLI Version: 3.12.0
  • Nitro Version: 2.9.6
  • Package Manager: pnpm@9.1.4
  • Builder: -
  • User Config: telemetry, ssr, app, sourcemap, colorMode, modules, formkit, pwa, runtimeConfig, security, css, vite, devServer
  • Runtime Modules: @pinia/nuxt@0.5.1, @vite-pwa/nuxt@0.8.1, @vueuse/nuxt@10.11.0, @formkit/nuxt@1.6.5, @nuxt/ui@2.17.0, nuxt-security@1.4.3
  • Build Modules: -

Version

2.17.0

Reproduction

https://stackblitz.com/edit/nuxt-ui-qs48un?file=app.vue

Description

When using the UTabs component, a Lazy component is never lazyloaded.

In the reproduction, you can see that the API call from Tab 2 is always called. However, If you put those Lazy components outside the UTabs and change it to selectedTab it works properly, as you can't see the API call.

<script setup>
const route = useRoute();
const router = useRouter();

const items = [
  {
    key: 'tab1',
    label: 'Tab1',
    content: 'This is the content shown for Tab1',
  },
  {
    key: 'tab2',

    label: 'Tab2',
    content: 'And, this is the content for Tab2',
  },
];

const selectedTab = computed({
  get() {
    const index = items.findIndex((item) => item.key === route.query.tab);
    if (index === -1) {
      return 0;
    }

    return index;
  },
  set(value) {
    router.replace({
      query: { tab: items[value].key },
    });
  },
});
</script>

<template>
  <UTabs v-model="selectedTab" :items="items">
    <template #item="{ item }">
      <LazyFirstComponent v-if="item.key === 'tab1'" />
      <LazyApiComponent v-if="item.key === 'tab2'" />
    </template>
  </UTabs>
</template>

Additional context

No response

Logs

No response

@Tragio Tragio added the bug Something isn't working label Jun 25, 2024
@Tragio Tragio changed the title Lazy component inside UTabs are not being lazyloaded Lazy component inside UTabs are never lazyloaded Jun 25, 2024
@noook
Copy link
Collaborator

noook commented Jun 26, 2024

Indeed, I can see that. Perhaps would the unmount prop handle your usecase ? This prop is meant for components not to be mounted unless the current tab is the appropriate one. This improves performance when using heavy components in each tab, and will re-run the request everytime you switch to this tab

@Tragio
Copy link
Contributor Author

Tragio commented Jun 27, 2024

Hi @noook 👋 ahhh yes, it solved, I never saw that prop 😅 perhaps we could improve the docs for that use-case?

@noook
Copy link
Collaborator

noook commented Jun 27, 2024

It's quite recent, I'm actually the one that introduced it for a very similar usecase!

If you'd like to submit a PR to improve the documentation feel free! Otherwise I can do it

@Tragio
Copy link
Contributor Author

Tragio commented Jun 27, 2024

Ahhh okido, so if you implemented it then you're more suitable than I for it 😋 however, if you don't have time I can do it. I'll keep the issue open until the upcoming PR is created and merged.

Thank you very much for your support 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants