We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 18e777f commit 7baa8e1Copy full SHA for 7baa8e1
vite-plugin-mock-dev-server/src/helper/defineMockData.ts
@@ -58,10 +58,18 @@ export function defineMockData<T = any>(
58
key: string,
59
initialData: T,
60
): MockData<T> {
61
- if (!mockDataCache.has(key))
62
- mockDataCache.set(key, new CacheImpl(initialData))
63
-
64
- const cache = mockDataCache.get(key)! as CacheImpl<T>
+ let cache = mockDataCache.get(key) as CacheImpl<T> | undefined
+ if (!cache) {
+ const newCache = new CacheImpl(initialData)
+ const existing = mockDataCache.get(key)
65
+ if (existing) {
66
+ cache = existing as CacheImpl<T>
67
+ }
68
+ else {
69
+ mockDataCache.set(key, newCache)
70
+ cache = newCache
71
72
73
74
cache.hotUpdate(initialData)
75
0 commit comments