Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(soup): list items not rendered because of query cancellation (#4134)

dev-rb079d5b069791
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx
index d16647e3aa..3a4af0c6be 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx
@@ -500,7 +500,7 @@ export const SoupViewContextProvider: FlowComponent<
queryOptions: () => {
const view = activeListView();
return {
- enabled: !search.isSearching(),
+ enabled: enabled() && !search.isSearching(),
meta: {
itemFilter: (item) => soupItemMatchesListView(item, view),
},
diff --git a/js/app/packages/queries/soup/normalized-cache/operations.ts b/js/app/packages/queries/soup/normalized-cache/operations.ts
index 9fc6a53ade..516d734f0a 100644
--- a/js/app/packages/queries/soup/normalized-cache/operations.ts
+++ b/js/app/packages/queries/soup/normalized-cache/operations.ts
@@ -9,6 +9,7 @@ import type { SoupPage } from '@service-storage/generated/schemas/soupPage';
import {
type InfiniteData,
partialMatchKey,
+ type Query,
type QueryKey,
} from '@tanstack/solid-query';
import { isAfter } from 'date-fns';
@@ -45,6 +46,19 @@ type SoupSearchInfiniteData = InfiniteData<
unknown
>;
+/**
+ * Cancel in-flight soup list refetches before an optimistic cache write.
+ *
+ * Only cancels queries that already have data. Cancelling an in-flight
+ * initial fetch (data === undefined) reverts it to a stuck pending/idle
+ * state, which leaves the soup view blank on refresh.
+ */
+function cancelSoupQueries() {
+ const predicate = (query: Query) => query.state.data !== undefined;
+ queryClient.cancelQueries({ queryKey: soupKeys.items._def, predicate });
+ queryClient.cancelQueries({ queryKey: soupKeys.astItems._def, predicate });
+}
+
/**
* Optimistically update a single soup entity across all queries that
* reference it. After normy's field merge, reconciles group membership in
@@ -56,11 +70,11 @@ type SoupSearchInfiniteData = InfiniteData<
* - Channels: `{ tag: 'channel', data: { channel: { id, ...fields } }, frecency_score }`
* - Everything else: `{ tag, data: { id, ...fields }, frecency_score }`
*/
+
export function optimisticUpdateSoupEntity<T extends SoupEntityTag>(
partial: SoupEntityPartial<T>
): SoupTransaction {
- queryClient.cancelQueries({ queryKey: soupKeys.items._def });
- queryClient.cancelQueries({ queryKey: soupKeys.astItems._def });
+ cancelSoupQueries();
const normalizer = getSoupNormalizer();
const normKey = getNormalizationObjectKey(partial);
@@ -144,8 +158,7 @@ export function getSoupItemId(item: SoupApiItem): string {
* and upsert into each resolvable group. Date / unresolved labels invalidate.
*/
export function insertSoupEntity(item: SoupApiItem): SoupTransaction {
- queryClient.cancelQueries({ queryKey: soupKeys.items._def });
- queryClient.cancelQueries({ queryKey: soupKeys.astItems._def });
+ cancelSoupQueries();
const previous = snapshotSoup();
queryClient.setQueriesData<SoupItemsInfiniteData>(
@@ -217,8 +230,7 @@ export function insertSoupEntity(item: SoupApiItem): SoupTransaction {
}
export function removeSoupEntities(entityIds: Set<string>): SoupTransaction {
- queryClient.cancelQueries({ queryKey: soupKeys.items._def });
- queryClient.cancelQueries({ queryKey: soupKeys.astItems._def });
+ cancelSoupQueries();
const previous = snapshotSoup();