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

Table rows dont get deleted / unmounted when data changes #3043

Open
MickL opened this issue Jan 8, 2025 · 0 comments
Open

Table rows dont get deleted / unmounted when data changes #3043

MickL opened this issue Jan 8, 2025 · 0 comments
Labels
bug Something isn't working triage v3 #1289

Comments

@MickL
Copy link
Contributor

MickL commented Jan 8, 2025

Version

v3 latest commit

Description

I noticed the following behavior:

  • When the data prop of a <UTable> changes, the rows dont get properly unmounted
  • This results in components within a row to never have unMounted being called (only if the amount of rows is less for the ones that get removed)
  • Further this can result in a bugs and unexpected behavior because for components only the props change but the setup function is not called again

Reproduction

Consider the following simplified example. The badge never changes color. Also if one would use onMounted/onUnmounted within the badge component they would not get triggered when the data changes (only if the amount of rows change).

my-badge.vue

<script setup lang="ts">
const props = defineProps<{
  status: 'yes' | 'no';
}>();

switch (props.status) {
  case 'yes':
    color = 'success';
    break;
  case 'no':
    color = 'error';
    break;
}
</script>

<template>
   <UBadge :color variant="subtle">{{ props.status }}</UBadge>
</template>

my-table.vue

<script setup lang="ts">
   const page = ref(1);
   const { data } = useFetch('url', { query: { page }}); // This gets refetched when `page.value` changes
</script>

<template>
  <UTable :data :columns>
     <template #status-cell="{ row }">
          <MyBadge :status="row.original.status" />
      </template>
  </UTable>
</template>

Additional context

I think this was already the case within v2: There I have a table that contains <NuxtImg /> tags. When the data changes (e.g. by pagination) the new rows are displayed with the images of the old row until the new images are loaded. That is probably because the <NuxtImg /> components dont get removed and replaced by all new ones.

Let me know if I should create a reproduction repo

@MickL MickL added bug Something isn't working triage v3 #1289 labels Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage v3 #1289
Projects
None yet
Development

No branches or pull requests

1 participant