Stop rereading provider snapshots while loading
This commit is contained in:
@@ -226,23 +226,21 @@ describe("providers snapshot hook cache scope", () => {
|
|||||||
await waitForSnapshotEntries(result, [codexEntry("ready", [readyCodexModel])]);
|
await waitForSnapshotEntries(result, [codexEntry("ready", [readyCodexModel])]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("refetches loading snapshot updates through the read path but ignores empty updates", async () => {
|
it("applies loading snapshot updates without refetching through the read path", async () => {
|
||||||
enableProvidersSnapshot();
|
enableProvidersSnapshot();
|
||||||
mockClient.getProvidersSnapshot
|
mockClient.getProvidersSnapshot.mockResolvedValueOnce(
|
||||||
.mockResolvedValueOnce(providersSnapshot([codexEntry("ready", [])]))
|
providersSnapshot([codexEntry("ready", [])]),
|
||||||
.mockResolvedValueOnce(providersSnapshot([codexEntry("ready", [readyCodexModel])]));
|
);
|
||||||
|
|
||||||
renderProvidersSnapshotHook();
|
const { result } = renderProvidersSnapshotHook();
|
||||||
|
|
||||||
await waitForSnapshotReads(1);
|
await waitForSnapshotReads(1);
|
||||||
await emitProvidersSnapshotUpdate([]);
|
|
||||||
|
|
||||||
|
const loadingEntries = [codexEntry("loading")];
|
||||||
|
await emitProvidersSnapshotUpdate(loadingEntries);
|
||||||
|
|
||||||
|
await waitForSnapshotEntries(result, loadingEntries);
|
||||||
expect(mockClient.getProvidersSnapshot).toHaveBeenCalledTimes(1);
|
expect(mockClient.getProvidersSnapshot).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
await emitProvidersSnapshotUpdate([codexEntry("loading")]);
|
|
||||||
await waitForSnapshotReads(2);
|
|
||||||
|
|
||||||
expect(mockClient.getProvidersSnapshot).toHaveBeenLastCalledWith({});
|
|
||||||
expect(mockClient.refreshProvidersSnapshot).not.toHaveBeenCalled();
|
expect(mockClient.refreshProvidersSnapshot).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -85,14 +85,6 @@ export function useProvidersSnapshot(
|
|||||||
generatedAt: message.payload.generatedAt,
|
generatedAt: message.payload.generatedAt,
|
||||||
requestId: "providers_snapshot_update",
|
requestId: "providers_snapshot_update",
|
||||||
});
|
});
|
||||||
const shouldRefetch = message.payload.entries.some((entry) => entry.status === "loading");
|
|
||||||
if (shouldRefetch) {
|
|
||||||
void queryClient.invalidateQueries({
|
|
||||||
queryKey: updateQueryKey,
|
|
||||||
exact: true,
|
|
||||||
refetchType: "active",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}, [client, enabled, isConnected, queryClient, serverId, supportsSnapshot]);
|
}, [client, enabled, isConnected, queryClient, serverId, supportsSnapshot]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user