From b612c32ce539985e3e16186a859969fbceed1e8a Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 13 Apr 2021 15:10:49 +0100 Subject: [PATCH] Fix stale data overwriting new data when requests are slow --- .../src/components/backend/DataTable/DataTable.svelte | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/components/backend/DataTable/DataTable.svelte b/packages/builder/src/components/backend/DataTable/DataTable.svelte index 8954b00f81..80b28d470b 100644 --- a/packages/builder/src/components/backend/DataTable/DataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/DataTable.svelte @@ -29,9 +29,18 @@ $: { if ($views.selected?.name?.startsWith("all_")) { loading = true + const loadingTableId = $tables.selected?._id api.fetchDataForView($views.selected).then(rows => { - data = rows || [] 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 || [] }) } }