TableBody component should respect isLoading state and not attempt to render empty state fallback during initial loading
material-react-table version
v3.1.0
react & react-dom versions
v18.2.0
Describe the bug and the steps to reproduce it
When isLoading is true, the table still attempts to access and render data properties, which can cause type errors. The table should not try to access or render any data during the initial loading state, and should only show the loading overlay.
Currently, the MRT_TableBody component only checks for empty rows (!rows.length) but doesn't consider the isLoading state. This causes two issues:
Type errors when accessing data properties during loading Unwanted empty state fallback being rendered behind the loading overlay
Steps to reproduce
- Create a table with async data loading:
const { data, isLoading } = useQuery(...)
const table = useMaterialReactTable({
data: data ?? [],
columns,
state: {
isLoading,
showLoadingOverlay: true
// when showSkeleton's value is false, Type Error occured
showSkeleton: false,
}
});
- During the initial loading state (isLoading: true):
- Type errors occur as the table tries to access data properties
- Empty state fallback is visible behind the loading overlay
- The table attempts to process data operations even though we're loading
Expected behavior
- When isLoading is true, the table should:
- Not attempt to access or process any data
- Not render the empty state fallback
- Only show the loading overlay
- Prevent any data-related operations until loading is complete
The MRT_TableBody component should check for isLoading state before attempting to render or process any data.
Minimal, Reproducible Example - (Optional, but Recommended)
const { data, isLoading } = useQuery(...)
const table = useMaterialReactTable({
data: data ?? [],
columns,
state: {
isLoading,
showLoadingOverlay: true
// when showSkeleton's value is false, Type Error occured
showSkeleton: false,
}
});
// MRT_TableBody.tsx
...
// does not check isLoading state
(!rows.length ? (
<tr
style={{
display: layoutMode?.startsWith('grid') ? 'grid' : undefined,
}}
>
<td
colSpan={table.getVisibleLeafColumns().length}
style={{
display: layoutMode?.startsWith('grid') ? 'grid' : undefined,
}}
>
...
Screenshots or Videos (Optional)
Do you intend to try to help solve this bug with your own PR?
Yes, I think I know how to fix it and will discuss it in the comments of this issue
Terms
- [x] I understand that if my bug cannot be reliably reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
any workaround on that?
https://github.com/KevinVandy/material-react-table/blob/8293b961523dc14878bf93af6122c6766e7c2233/packages/material-react-table/src/hooks/useMRT_TableInstance.ts#L222-L249
Here the logic shows isLoading || showSkeletons
statefulTableOptions.state.isLoading ||
statefulTableOptions.state.showSkeletons
While it seems to me that it should be isLoading && showSkeletons
@meesvandongen I agree Can I fix and open pull request?
I am no maintainer so I have no influence here whatsoever. Though I imagine @KevinVandy would be happy to merge it.
any workaround on that?
@kamaladafrica I turn off showSekeletons flags and apply custom loading UI (add spinning row when state.isLoading is true)