Skip to content

Commit cd2662a

Browse files
fix(Table): empty cell value causing hydration errors (#5069)
Co-authored-by: Benjamin Canac <[email protected]>
1 parent 43c119f commit cd2662a

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/runtime/components/Table.vue

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,30 @@ const { t } = useLocale()
221221
const appConfig = useAppConfig() as Table['AppConfig']
222222
223223
const data = ref(props.data ?? []) as Ref<T[]>
224-
const columns = computed<TableColumn<T>[]>(() => props.columns ?? Object.keys(data.value[0] ?? {}).map((accessorKey: string) => ({ accessorKey, header: upperFirst(accessorKey) })))
225224
const meta = computed(() => props.meta ?? {})
225+
const columns = computed<TableColumn<T>[]>(() => processColumns(props.columns ?? Object.keys(data.value[0] ?? {}).map((accessorKey: string) => ({ accessorKey, header: upperFirst(accessorKey) }))))
226+
227+
function processColumns(columns: TableColumn<T>[]): TableColumn<T>[] {
228+
return columns.map((column) => {
229+
const col = { ...column } as TableColumn<T>
230+
231+
if ('columns' in col && col.columns) {
232+
col.columns = processColumns(col.columns as TableColumn<T>[])
233+
}
234+
235+
if (!col.cell) {
236+
col.cell = ({ getValue }) => {
237+
const value = getValue()
238+
if (value === '' || value === null || value === undefined) {
239+
return '\u00A0'
240+
}
241+
return String(value)
242+
}
243+
}
244+
245+
return col
246+
})
247+
}
226248
227249
const ui = computed(() => tv({ extend: tv(theme), ...(appConfig.ui?.table || {}) })({
228250
sticky: props.sticky,

0 commit comments

Comments
 (0)