Skip to content

Commit 58b68fe

Browse files
committed
update debounce to set on file and event type
1 parent acc85ca commit 58b68fe

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

packages/theme/src/cli/utilities/theme-fs.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,23 +270,24 @@ export function mountThemeFileSystem(root: string, options?: ThemeFileSystemOpti
270270
ignoreInitial: true,
271271
})
272272

273-
// Debounce file events per-file
274-
const pendingEvents = new Map<string, {eventName: 'add' | 'change' | 'unlink'; timeout: NodeJS.Timeout}>()
273+
// Debounce file events per-file and per-event-type
274+
const pendingEvents = new Map<string, NodeJS.Timeout>()
275275

276276
const queueFsEvent = (eventName: 'add' | 'change' | 'unlink', filePath: string) => {
277277
const fileKey = getKey(filePath)
278+
const eventKey = `${fileKey}:${eventName}`
278279

279-
const pending = pendingEvents.get(fileKey)
280+
const pending = pendingEvents.get(eventKey)
280281
if (pending) {
281-
clearTimeout(pending.timeout)
282+
clearTimeout(pending)
282283
}
283284

284285
const timeout = setTimeout(() => {
285-
pendingEvents.delete(fileKey)
286+
pendingEvents.delete(eventKey)
286287
handleFsEvent(eventName, themeId, adminSession, filePath)
287288
}, FILE_EVENT_DEBOUNCE_TIME_IN_MS)
288289

289-
pendingEvents.set(fileKey, {eventName, timeout})
290+
pendingEvents.set(eventKey, timeout)
290291
}
291292

292293
watcher

0 commit comments

Comments
 (0)