mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-02 11:40:00 +00:00
Reland "Fix undo / redo filling with empty steps" (#1653)
* Revert "Revert "Fix undo / redo filling with empty steps (#1649)" (#1652)" This reverts commit7623810166. * Update test expectations * Add dirty flag if workflow is not persisted * Add dirty flag to other UI areas for new workflows * Remove redundant code * Fix regression: undo / redo steps lost on refresh The history is still be cleared, but any changes made by issuing undo / redo comands prior to refresh are not lost. * Update test expectations Partially revertsf8cc2c0d67- adds dirty flags back to unsaved workflows. --------- Co-authored-by: filtered <176114999+webfiltered@users.noreply.github.com>
This commit is contained in:
@@ -10,15 +10,7 @@ import _ from 'lodash'
|
||||
import * as jsondiffpatch from 'jsondiffpatch'
|
||||
import log from 'loglevel'
|
||||
|
||||
function clone(obj: any) {
|
||||
try {
|
||||
if (typeof structuredClone !== 'undefined') {
|
||||
return structuredClone(obj)
|
||||
}
|
||||
} catch (error) {
|
||||
// structuredClone is stricter than using JSON.parse/stringify so fallback to that
|
||||
}
|
||||
|
||||
function clone<T>(obj: T): T {
|
||||
return JSON.parse(JSON.stringify(obj))
|
||||
}
|
||||
|
||||
@@ -69,7 +61,7 @@ export class ChangeTracker {
|
||||
if (this.restoringState) return
|
||||
|
||||
logger.debug('Reset State')
|
||||
this.activeState = state ?? this.activeState
|
||||
if (state) this.activeState = clone(state)
|
||||
this.initialState = clone(this.activeState)
|
||||
}
|
||||
|
||||
@@ -91,6 +83,10 @@ export class ChangeTracker {
|
||||
}
|
||||
|
||||
updateModified() {
|
||||
api.dispatchEvent(
|
||||
new CustomEvent('graphChanged', { detail: this.activeState })
|
||||
)
|
||||
|
||||
// Get the workflow from the store as ChangeTracker is raw object, i.e.
|
||||
// `this.workflow` is not reactive.
|
||||
const workflow = useWorkflowStore().getWorkflowByPath(this.workflow.path)
|
||||
@@ -112,9 +108,9 @@ export class ChangeTracker {
|
||||
checkState() {
|
||||
if (!this.app.graph || this.changeCount) return
|
||||
// @ts-expect-error zod types issue. Will be fixed after we enable ts-strict
|
||||
const currentState = this.app.graph.serialize() as ComfyWorkflowJSON
|
||||
const currentState = clone(this.app.graph.serialize()) as ComfyWorkflowJSON
|
||||
if (!this.activeState) {
|
||||
this.activeState = clone(currentState)
|
||||
this.activeState = currentState
|
||||
return
|
||||
}
|
||||
if (!ChangeTracker.graphEqual(this.activeState, currentState)) {
|
||||
@@ -124,11 +120,8 @@ export class ChangeTracker {
|
||||
}
|
||||
logger.debug('Diff detected. Undo queue length:', this.undoQueue.length)
|
||||
|
||||
this.activeState = clone(currentState)
|
||||
this.activeState = currentState
|
||||
this.redoQueue.length = 0
|
||||
api.dispatchEvent(
|
||||
new CustomEvent('graphChanged', { detail: this.activeState })
|
||||
)
|
||||
this.updateModified()
|
||||
}
|
||||
}
|
||||
@@ -136,7 +129,7 @@ export class ChangeTracker {
|
||||
async updateState(source: ComfyWorkflowJSON[], target: ComfyWorkflowJSON[]) {
|
||||
const prevState = source.pop()
|
||||
if (prevState) {
|
||||
target.push(this.activeState!)
|
||||
target.push(this.activeState)
|
||||
this.restoringState = true
|
||||
try {
|
||||
await this.app.loadGraphData(prevState, false, false, this.workflow, {
|
||||
|
||||
Reference in New Issue
Block a user