Skip to content

Commit 03598be

Browse files
committed
refactor: tighten audit-pass leak fixes
- store.ts softDeleteDesign: skip Set clone + set() when id not in autoPolishFired, so subscribers aren't notified on a no-op delete - DesignCardPreview readCache: route hit path through memCacheTouch instead of duplicating delete+set inline - overlay.ts: drop the redundant if (__cs_reattach_interval) guard before clearInterval — clearInterval is safe on undefined/0 Review follow-up to 6b8cfbc; runtime tests 15/15, desktop typecheck clean.
1 parent 6b8cfbc commit 03598be

3 files changed

Lines changed: 11 additions & 17 deletions

File tree

apps/desktop/src/renderer/src/store.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,9 +1679,11 @@ export const useCodesignStore = create<CodesignState>((set, get) => ({
16791679
}
16801680
try {
16811681
await window.codesign.snapshots.softDeleteDesign(id);
1682-
const nextFired = new Set(get().autoPolishFired);
1683-
nextFired.delete(id);
1684-
set({ autoPolishFired: nextFired });
1682+
if (get().autoPolishFired.has(id)) {
1683+
const nextFired = new Set(get().autoPolishFired);
1684+
nextFired.delete(id);
1685+
set({ autoPolishFired: nextFired });
1686+
}
16851687
const wasCurrent = get().currentDesignId === id;
16861688
await get().loadDesigns();
16871689
if (wasCurrent) {

apps/desktop/src/renderer/src/views/hub/DesignCardPreview.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ function cacheKey(id: string, updatedAt: string): string {
5656
return `${id}:${updatedAt}`;
5757
}
5858

59-
// Map iteration order = insertion order, so delete+set on hit refreshes recency
60-
// and evicting the first key drops the least-recently-used entry.
59+
// Map preserves insertion order, so delete+set on access makes the eviction
60+
// loop drop the least-recently-used key when the cache overflows.
6161
function memCacheTouch(key: string, value: string): void {
6262
memCache.delete(key);
6363
memCache.set(key, value);
@@ -71,8 +71,7 @@ function memCacheTouch(key: string, value: string): void {
7171
function readCache(key: string): string | null {
7272
const hit = memCache.get(key);
7373
if (hit !== undefined) {
74-
memCache.delete(key);
75-
memCache.set(key, hit);
74+
memCacheTouch(key, hit);
7675
return hit;
7776
}
7877
if (typeof localStorage === 'undefined') return null;

packages/runtime/src/overlay.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,13 @@ export const OVERLAY_SCRIPT = `(function() {
208208
}
209209
reattach();
210210
try {
211-
if (window.__cs_reattach_interval) {
212-
try { clearInterval(window.__cs_reattach_interval); } catch (_) {}
213-
window.__cs_reattach_interval = 0;
214-
}
211+
try { clearInterval(window.__cs_reattach_interval); } catch (_) {}
215212
window.__cs_reattach_interval = setInterval(reattach, 200);
216213
if (!window.__cs_reattach_unload) {
217214
window.__cs_reattach_unload = true;
218215
var stopReattach = function() {
219-
try {
220-
if (window.__cs_reattach_interval) {
221-
clearInterval(window.__cs_reattach_interval);
222-
window.__cs_reattach_interval = 0;
223-
}
224-
} catch (_) {}
216+
try { clearInterval(window.__cs_reattach_interval); } catch (_) {}
217+
window.__cs_reattach_interval = 0;
225218
};
226219
try { window.addEventListener('pagehide', stopReattach, false); } catch (_) {}
227220
try { window.addEventListener('beforeunload', stopReattach, false); } catch (_) {}

0 commit comments

Comments
 (0)