Skip to content

Commit d0f9f49

Browse files
committed
wip: fix front-end lag issue
1 parent 410b811 commit d0f9f49

2 files changed

Lines changed: 52 additions & 36 deletions

File tree

frontend/src/components/FormGenerator.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,19 @@ const setBaseYamlFromSource = (source) => {
297297
}
298298
try {
299299
let parsed = source
300+
let yamlString = ''
300301
if (typeof source === 'string') {
302+
yamlString = source
301303
parsed = yaml.load(source) || {}
302304
} else if (typeof source === 'object') {
303305
parsed = JSON.parse(JSON.stringify(source))
304306
} else {
305307
parsed = {}
306308
}
307309
baseYamlObject.value = parsed
308-
baseYamlString.value = yaml.dump(parsed ?? null, yamlDumpOptions)
310+
// Avoid expensive dump on modal open for object sources.
311+
// Save path will generate YAML from current object when needed.
312+
baseYamlString.value = yamlString
309313
} catch (error) {
310314
console.error('Failed to set base YAML from provided source:', error)
311315
baseYamlObject.value = null
@@ -1046,7 +1050,7 @@ watch(() => props.initialYaml, (newValue) => {
10461050
baseYamlObject.value = null
10471051
baseYamlString.value = ''
10481052
}
1049-
}, { immediate: true, deep: true })
1053+
}, { immediate: true })
10501054
10511055
watch(() => props.workflowName, async (newName, oldName) => {
10521056
if (!newName) {

frontend/src/pages/WorkflowView.vue

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,67 +1294,81 @@ const updateVueFlowNodeId = (oldId, newId) => {
12941294
// FormGenerator integration
12951295
const snapshotYamlContent = () => cloneDeep(yamlContent.value ?? null)
12961296

1297-
// Build YAML without specific node
1297+
// Build YAML without specific node (shallow clone path to avoid full deep-clone on editor open)
12981298
const buildYamlWithoutNode = (nodeId) => {
1299-
const snapshot = snapshotYamlContent()
1300-
if (!snapshot?.graph?.nodes || !Array.isArray(snapshot.graph.nodes)) {
1301-
return snapshot
1299+
const source = yamlContent.value
1300+
if (!source?.graph?.nodes || !Array.isArray(source.graph.nodes)) {
1301+
return source
1302+
}
1303+
return {
1304+
...source,
1305+
graph: {
1306+
...source.graph,
1307+
nodes: source.graph.nodes.filter(node => node?.id !== nodeId)
1308+
}
13021309
}
1303-
snapshot.graph.nodes = snapshot.graph.nodes.filter(node => node?.id !== nodeId)
1304-
return snapshot
13051310
}
13061311

13071312
const buildYamlWithoutEdge = (fromId, toId) => {
1308-
const snapshot = snapshotYamlContent()
1309-
if (!snapshot?.graph?.edges || !Array.isArray(snapshot.graph.edges)) {
1310-
return snapshot
1313+
const source = yamlContent.value
1314+
if (!source?.graph?.edges || !Array.isArray(source.graph.edges)) {
1315+
return source
13111316
}
13121317
let removed = false
1313-
snapshot.graph.edges = snapshot.graph.edges.filter(edge => {
1318+
const filteredEdges = source.graph.edges.filter(edge => {
13141319
if (!removed && edge?.from === fromId && edge?.to === toId) {
13151320
removed = true
13161321
return false
13171322
}
13181323
return true
13191324
})
1320-
return snapshot
1325+
return {
1326+
...source,
1327+
graph: {
1328+
...source.graph,
1329+
edges: filteredEdges
1330+
}
1331+
}
13211332
}
13221333

13231334
const buildYamlWithoutVars = () => {
1324-
const snapshot = snapshotYamlContent()
1325-
if (!snapshot || typeof snapshot !== 'object') {
1326-
return snapshot
1335+
const source = yamlContent.value
1336+
if (!source || typeof source !== 'object') {
1337+
return source
13271338
}
1328-
if (!Object.prototype.hasOwnProperty.call(snapshot, 'vars')) {
1329-
return snapshot
1339+
if (!Object.prototype.hasOwnProperty.call(source, 'vars')) {
1340+
return source
13301341
}
1331-
const sanitized = { ...snapshot }
1342+
const sanitized = { ...source }
13321343
delete sanitized.vars
13331344
return sanitized
13341345
}
13351346

13361347
const buildYamlWithoutMemory = () => {
1337-
const snapshot = snapshotYamlContent()
1338-
if (!snapshot?.graph) {
1339-
return snapshot
1348+
const source = yamlContent.value
1349+
if (!source?.graph) {
1350+
return source
13401351
}
1341-
if (Object.prototype.hasOwnProperty.call(snapshot.graph, 'memory')) {
1342-
const newGraph = { ...snapshot.graph }
1352+
if (Object.prototype.hasOwnProperty.call(source.graph, 'memory')) {
1353+
const newGraph = { ...source.graph }
13431354
delete newGraph.memory
1344-
snapshot.graph = newGraph
1355+
return {
1356+
...source,
1357+
graph: newGraph
1358+
}
13451359
}
1346-
return snapshot
1360+
return source
13471361
}
13481362

13491363
const buildYamlWithoutGraph = () => {
1350-
const snapshot = snapshotYamlContent()
1351-
if (!snapshot || typeof snapshot !== 'object') {
1352-
return snapshot
1364+
const source = yamlContent.value
1365+
if (!source || typeof source !== 'object') {
1366+
return source
13531367
}
1354-
if (!Object.prototype.hasOwnProperty.call(snapshot, 'graph')) {
1355-
return snapshot
1368+
if (!Object.prototype.hasOwnProperty.call(source, 'graph')) {
1369+
return source
13561370
}
1357-
const sanitized = { ...snapshot }
1371+
const sanitized = { ...source }
13581372
delete sanitized.graph
13591373
return sanitized
13601374
}
@@ -1398,12 +1412,10 @@ const openDynamicFormGenerator = (type, options = {}) => {
13981412

13991413
const hasCustomYaml = Object.prototype.hasOwnProperty.call(options, 'initialYaml')
14001414
const yamlSource = hasCustomYaml ? options.initialYaml : yamlContent.value
1401-
formGeneratorInitialYaml.value = yamlSource ? cloneDeep(yamlSource) : null
1415+
formGeneratorInitialYaml.value = yamlSource || null
14021416

14031417
if (Object.prototype.hasOwnProperty.call(options, 'initialFormData')) {
1404-
formGeneratorInitialFormData.value = options.initialFormData
1405-
? cloneDeep(options.initialFormData)
1406-
: null
1418+
formGeneratorInitialFormData.value = options.initialFormData || null
14071419
} else {
14081420
formGeneratorInitialFormData.value = null
14091421
}

0 commit comments

Comments
 (0)