-
Notifications
You must be signed in to change notification settings - Fork 961
Description
Environment
- Operating System: Windows_NT
- Node Version: v22.19.0
- Nuxt Version: 4.1.2
- CLI Version: 3.30.0
- Nitro Version: 2.12.6
- Package Manager: pnpm@10.19.0
- Builder: -
- User Config: compatibilityDate, devtools, runtimeConfig, css, modules, routeRules
- Runtime Modules: @nuxt/eslint@1.9.0, @nuxt/ui@4.1.0
- Build Modules: -
Is this bug related to Nuxt or Vue?
Nuxt
Package
v4.x
Version
v4.1.0
Reproduction
<script setup lang="ts">
const table = useTemplateRef('table');
const rowSelection = ref<Record<string, boolean>>({});
// data and columns definitions............
function onUpdateRowSelection() {
// This shows the PREVIOUS state, not the current one
const immediateSelection = table.value?.tableApi
.getFilteredSelectedRowModel()
.rows.map((row) => row.original.id);
console.log('Immediate Selection ❌: ', immediateSelection); // []
setTimeout(() => {
// This shows the CORRECT state, but it's delayed
const delayedSelection = table.value?.tableApi
.getFilteredSelectedRowModel()
.rows.map((row) => row.original.id);
console.log('Delayed Selection ✔️: ', delayedSelection); // ['962464e7-7b35-4ee6-a555-c839a33d110c']
}, 5000);
}
</script>
<template>
<UTable
ref="table"
v-model:row-selection="rowSelection"
:data="data"
:columns="columns"
@update:row-selection="onUpdateRowSelection"
/>
</template>Description
I'm experiencing what appears to be a synchronization issue when using the UTable component with row selection. I'm not entirely sure if this is a bug in the component or if I'm implementing something incorrectly, but I wanted to report it in case others are facing similar problems.
When using the UTable component with v-model:row-selection, there seems to be a timing issue between the update:row-selection event and the internal state of the table. The event appears to be emitted before the internal TanStack Table state is fully updated, which causes inconsistencies when trying to access the currently selected rows immediately after the event fires.
Expected Behavior
- The internal table state should already be updated.
tableApi.getFilteredSelectedRowModel().rowsshould return the current selection.- The table API should be synchronized with the
rowSelectionref.
Actual Behavior
- The
update:row-selectionevent fires before the internal table state updates. tableApi.getFilteredSelectedRowModel().rowsreturns the previous selection state.- The
rowSelectionref itself is being updated properly. - Accessing the current selection requires using
setTimeoutor similar workarounds.
This issue is problematic when performing immediate operations on selected rows after selection changes, or using watches that depends on the current selection state.
I'm not sure if I'm using the component incorrectly, if this is indeed a bug, or if it's related to the underlying TanStack Table. Could you please help clarify the intended behavior and whether there's a proper way to access the current selection?
Additional context
No response