Skip to content

Commit 2d945ff

Browse files
committed
Should check for staleTime
1 parent ee40334 commit 2d945ff

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

packages/mst-query/src/MstQueryHandler.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,14 @@ export class QueryObserver {
136136
this.handler.type,
137137
options.cacheKey,
138138
);
139-
const isStale = !cacheEntry || isDataStale(cacheEntry.cachedAt, options.cacheTime);
139+
if (cacheEntry) {
140+
this.handler.hydrate(cacheEntry.data, options);
141+
}
142+
143+
const isStale = !cacheEntry || isDataStale(cacheEntry.cachedAt, options.staleTime);
140144
if (isStale) {
141145
this.handler.queryWhenChanged(options);
142-
} else {
143-
try {
144-
this.handler.hydrate(cacheEntry.data, options);
145-
} catch {
146-
this.handler.queryWhenChanged(options);
147-
}
148-
}
146+
}
149147
} else {
150148
if (!options.isRequestEqual) {
151149
this.query.setData(null);

packages/mst-query/tests/mstQuery.test.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ test('useQuery - cacheKey and cacheTime', async () => {
242242
request: { id: id.get() },
243243
cacheKey: id.get(),
244244
cacheTime: 25,
245+
staleTime: 25,
245246
meta: { getItem: testApi.getItem },
246247
});
247248
return <div></div>;

0 commit comments

Comments
 (0)