Skip to content

Commit bb6a1cf

Browse files
committed
update debounce to set on file and event type
1 parent a910517 commit bb6a1cf

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
@@ -323,23 +323,24 @@ export function mountThemeFileSystem(root: string, options?: ThemeFileSystemOpti
323323
ignoreInitial: true,
324324
})
325325

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

329329
const queueFsEvent = (eventName: 'add' | 'change' | 'unlink', filePath: string) => {
330330
const fileKey = getKey(filePath)
331+
const eventKey = `${fileKey}:${eventName}`
331332

332-
const pending = pendingEvents.get(fileKey)
333+
const pending = pendingEvents.get(eventKey)
333334
if (pending) {
334-
clearTimeout(pending.timeout)
335+
clearTimeout(pending)
335336
}
336337

337338
const timeout = setTimeout(() => {
338-
pendingEvents.delete(fileKey)
339+
pendingEvents.delete(eventKey)
339340
handleFsEvent(eventName, themeId, adminSession, filePath)
340341
}, FILE_EVENT_DEBOUNCE_TIME_IN_MS)
341342

342-
pendingEvents.set(fileKey, {eventName, timeout})
343+
pendingEvents.set(eventKey, timeout)
343344
}
344345

345346
watcher

0 commit comments

Comments
 (0)