Skip to content

DataGrid reload() is a no-op: the list is never refetched #124

Description

@jonasnobile

What happens

reload() from the data view context does nothing in DataGrid, HasManyDataGrid and SelectDataView. The list is never fetched again, so the toolbar's reload button (DataViewReloadTrigger) and any useDataViewReload() call after a row action leave stale rows on screen.

All three implement it as a counter that nothing reads (packages/bindx-dataview/src/DataGrid.tsx:144, same in HasManyDataGrid.tsx:251 and select/SelectDataView.tsx:199):

const [, setReloadCounter] = useState(0)
const reload = useCallback((): void => {
	setReloadCounter(c => c + 1)
}, [])

The counter is not passed to useEntityList (queryKey) or useEntityCount (refreshToken), so the re-render it causes hits the same cached query.

Seen on 0.1.52 and on main (78c1712).

Repro

  1. A DataGrid over tasks filtered to open ones (finishedAt: { isNull: true }).
  2. A row action that sets finishedAt through a separate mutation (not the grid's own store), then calls useDataViewReload()().
  3. The finished task stays in the list until the page is reloaded. Clicking the toolbar reload button changes nothing either.

Expected

reload() refetches the current page and the total count with the current filter, sort and paging, keeping the rows on screen while it loads (loader state refreshing).

Possible fix

Fold the counter into the key the list query is cached under and into the count's refresh token, e.g. in DataGrid:

const [reloadCounter, setReloadCounter] = useState(0)
const result = useEntityList(entity, { ..., queryKey: `${setup.queryKey}:${reloadCounter}` })
const { count } = useEntityCount(entity, { filter: setup.combinedFilter, refreshToken: setup.paging.totalCountRefreshToken + reloadCounter })

and the equivalent for the paginateRelation load in HasManyDataGrid and for SelectDataView.

Workaround we use

Changing the grid's filter with a match-all condition that carries a counter (id: { notEq: '00000000-0000-0000-0000-<counter>' }), which forces a new query: prosam-crm admin/src/components/data-grid/reload.ts.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions