Fix stale data overwriting new data when requests are slow

This commit is contained in:
Andrew Kingston 2021-04-13 15:10:49 +01:00
parent 0f56ed3c95
commit b612c32ce5
1 changed files with 10 additions and 1 deletions

View File

@ -29,9 +29,18 @@
$: { $: {
if ($views.selected?.name?.startsWith("all_")) { if ($views.selected?.name?.startsWith("all_")) {
loading = true loading = true
const loadingTableId = $tables.selected?._id
api.fetchDataForView($views.selected).then(rows => { api.fetchDataForView($views.selected).then(rows => {
data = rows || []
loading = false loading = false
// If we started a slow request then quickly change table, sometimes
// the old data overwrites the new data.
// This check ensures that we don't do that.
if (loadingTableId !== $tables.selected?._id) {
return
}
data = rows || []
}) })
} }
} }