From 194a135183d3a0faef77402442cf6eacd91eaa9e Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 9 Jun 2023 13:11:18 +0100 Subject: [PATCH] Reset rows and tick before updating schema when swapping table ID in grids --- .../frontend-core/src/components/grid/stores/rows.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/frontend-core/src/components/grid/stores/rows.js b/packages/frontend-core/src/components/grid/stores/rows.js index d7e623692e..1a98ef1848 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.js +++ b/packages/frontend-core/src/components/grid/stores/rows.js @@ -121,13 +121,22 @@ export const deriveStores = context => { }) // Subscribe to changes of this fetch model - unsubscribe = newFetch.subscribe($fetch => { + unsubscribe = newFetch.subscribe(async $fetch => { if ($fetch.loaded && !$fetch.loading) { hasNextPage.set($fetch.hasNextPage) const $instanceLoaded = get(instanceLoaded) const resetRows = $fetch.resetKey !== lastResetKey + const previousResetKey = lastResetKey lastResetKey = $fetch.resetKey + // If resetting rows due to a table change, wipe data and wait for + // derived stores to compute. This prevents stale data being passed + // to cells when we save the new schema. + if (!$instanceLoaded && previousResetKey) { + rows.set([]) + await tick() + } + // Reset state properties when dataset changes if (!$instanceLoaded || resetRows) { table.set($fetch.definition)