Compare commits
2 Commits
audit-fixes
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6648d4b9d6 | |||
| caab0a4eeb |
+36
-24
@@ -1778,9 +1778,10 @@ async function restoreSnapshot(record) {
|
||||
if (!full) { showToast("Failed to load snapshot data", "error"); return; }
|
||||
record = full;
|
||||
}
|
||||
// Preserve any unsaved live edits before replacing the canvas (parity with
|
||||
// swap). Deduped by hash, so it's a no-op when there is nothing new to save.
|
||||
await captureSnapshot("Current").catch(() => {});
|
||||
// Preserve any unsaved meaningful edit before replacing the canvas (parity
|
||||
// with swap). Deduped by hash and skips cosmetic-only changes, so it's a
|
||||
// no-op when there is nothing meaningful new to save.
|
||||
await captureSnapshot("Current", { skipCosmetic: true }).catch(() => {});
|
||||
await withRestoreLock(async () => {
|
||||
if (!validateSnapshotData(record.graphData)) {
|
||||
showToast("Invalid snapshot data", "error");
|
||||
@@ -1789,8 +1790,13 @@ async function restoreSnapshot(record) {
|
||||
try {
|
||||
await app.loadGraphData(record.graphData, true, true);
|
||||
const wfKey = getWorkflowKey();
|
||||
lastCapturedHashMap.set(wfKey, quickHash(JSON.stringify(record.graphData)));
|
||||
setLastGraphData(wfKey, record.graphData);
|
||||
// Seed the dedup baseline from the LIVE re-serialization, not the
|
||||
// stored record: ComfyUI's serialize() of the loaded graph isn't
|
||||
// byte-identical to the saved bytes, so seeding from record.graphData
|
||||
// makes the next captureSnapshot() hash mismatch and spuriously save.
|
||||
const liveGraph = getGraphData() || record.graphData;
|
||||
lastCapturedHashMap.set(wfKey, quickHash(JSON.stringify(liveGraph)));
|
||||
setLastGraphData(wfKey, liveGraph);
|
||||
showToast("Snapshot restored", "success");
|
||||
} catch (err) {
|
||||
console.warn(`[${EXTENSION_NAME}] Restore failed:`, err);
|
||||
@@ -1814,8 +1820,11 @@ async function swapSnapshot(record, { quiet = false } = {}) {
|
||||
// between already-saved snapshots, but it WILL save any unsaved live edits
|
||||
// made after a previous swap (when activeSnapshotId is still set) — which
|
||||
// would otherwise be silently discarded by the load below.
|
||||
// Preserve a genuine unsaved edit before loading, but skip cosmetic-only
|
||||
// changes (move/resize/collapse) and dedup no-ops so that merely browsing
|
||||
// between snapshots never spawns a "Current" snapshot (the reported spam).
|
||||
const prevCurrentId = currentSnapshotId;
|
||||
const capturedId = await captureSnapshot("Current");
|
||||
const capturedId = await captureSnapshot("Current", { skipCosmetic: true });
|
||||
currentSnapshotId = capturedId || prevCurrentId;
|
||||
|
||||
if (!record.graphData) {
|
||||
@@ -1833,8 +1842,14 @@ async function swapSnapshot(record, { quiet = false } = {}) {
|
||||
const workflow = app.extensionManager?.workflow?.activeWorkflow;
|
||||
await app.loadGraphData(record.graphData, true, true, workflow);
|
||||
const wfKey = getWorkflowKey();
|
||||
lastCapturedHashMap.set(wfKey, quickHash(JSON.stringify(record.graphData)));
|
||||
setLastGraphData(wfKey, record.graphData);
|
||||
// Seed the dedup baseline from the LIVE re-serialization, not the
|
||||
// stored record: ComfyUI's serialize() of the loaded graph isn't
|
||||
// byte-identical to the saved bytes, so seeding from record.graphData
|
||||
// makes the next captureSnapshot() hash mismatch and spuriously save a
|
||||
// "Current" snapshot on every swap (the reported timeline-swap spam).
|
||||
const liveGraph = getGraphData() || record.graphData;
|
||||
lastCapturedHashMap.set(wfKey, quickHash(JSON.stringify(liveGraph)));
|
||||
setLastGraphData(wfKey, liveGraph);
|
||||
activeSnapshotId = record.id;
|
||||
if (!quiet) showToast("Snapshot swapped", "success");
|
||||
} catch (err) {
|
||||
@@ -4396,12 +4411,16 @@ if (window.__COMFYUI_FRONTEND_VERSION__) {
|
||||
activeBranchSelections.clear();
|
||||
// Seed active ring for the new workflow tab
|
||||
const newKey = getWorkflowKey();
|
||||
// Re-seed the dedup/change-detection baseline for the new
|
||||
// tab and suppress auto-capture briefly, so the graphChanged
|
||||
// fired by loading this workflow doesn't spawn a redundant
|
||||
// "Auto" snapshot of a workflow the user only just opened.
|
||||
seedWorkflowBaseline(newKey);
|
||||
suppressAutoCapture(SWITCH_GUARD_MS);
|
||||
// Suppress auto-capture briefly so the graphChanged fired
|
||||
// by loading this workflow doesn't spawn a redundant "Auto"
|
||||
// snapshot of a workflow the user only just opened. Guard
|
||||
// everything so a failure here can never break the switch.
|
||||
try {
|
||||
suppressAutoCapture(SWITCH_GUARD_MS);
|
||||
seedWorkflowBaseline(newKey);
|
||||
} catch (err) {
|
||||
console.warn(`[${EXTENSION_NAME}] post-switch seeding failed:`, err);
|
||||
}
|
||||
trackSessionWorkflow(newKey);
|
||||
db_getAllForWorkflow(newKey).then(recs => {
|
||||
if (recs.length > 0 && !lastCapturedIdMap.has(newKey)) {
|
||||
@@ -4436,16 +4455,9 @@ if (window.__COMFYUI_FRONTEND_VERSION__) {
|
||||
}
|
||||
});
|
||||
|
||||
// Alt+Left / Alt+Right step non-destructively through snapshot history
|
||||
// (Fusion-360 "roll the history marker" feel — jump back/forth freely).
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (!e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;
|
||||
if (e.key !== "ArrowLeft" && e.key !== "ArrowRight") return;
|
||||
const t = e.target;
|
||||
if (t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.isContentEditable)) return;
|
||||
e.preventDefault();
|
||||
stepToSnapshot(e.key === "ArrowLeft" ? -1 : 1).catch(() => {});
|
||||
});
|
||||
// (Keyboard step-navigation removed: a global Alt+Left/Right handler
|
||||
// collides with the browser's Back/Forward. stepToSnapshot() remains
|
||||
// for a future, conflict-free binding or a timeline button.)
|
||||
|
||||
// Build the timeline bar on the canvas
|
||||
buildTimeline();
|
||||
|
||||
Reference in New Issue
Block a user