wip: fix front-end lag issue

This commit is contained in:
Shu Yao 2026-02-06 11:53:09 +08:00
parent 410b8112b4
commit d0f9f4966b
2 changed files with 52 additions and 36 deletions

View File

@ -297,7 +297,9 @@ const setBaseYamlFromSource = (source) => {
} }
try { try {
let parsed = source let parsed = source
let yamlString = ''
if (typeof source === 'string') { if (typeof source === 'string') {
yamlString = source
parsed = yaml.load(source) || {} parsed = yaml.load(source) || {}
} else if (typeof source === 'object') { } else if (typeof source === 'object') {
parsed = JSON.parse(JSON.stringify(source)) parsed = JSON.parse(JSON.stringify(source))
@ -305,7 +307,9 @@ const setBaseYamlFromSource = (source) => {
parsed = {} parsed = {}
} }
baseYamlObject.value = parsed baseYamlObject.value = parsed
baseYamlString.value = yaml.dump(parsed ?? null, yamlDumpOptions) // Avoid expensive dump on modal open for object sources.
// Save path will generate YAML from current object when needed.
baseYamlString.value = yamlString
} catch (error) { } catch (error) {
console.error('Failed to set base YAML from provided source:', error) console.error('Failed to set base YAML from provided source:', error)
baseYamlObject.value = null baseYamlObject.value = null
@ -1046,7 +1050,7 @@ watch(() => props.initialYaml, (newValue) => {
baseYamlObject.value = null baseYamlObject.value = null
baseYamlString.value = '' baseYamlString.value = ''
} }
}, { immediate: true, deep: true }) }, { immediate: true })
watch(() => props.workflowName, async (newName, oldName) => { watch(() => props.workflowName, async (newName, oldName) => {
if (!newName) { if (!newName) {

View File

@ -1294,67 +1294,81 @@ const updateVueFlowNodeId = (oldId, newId) => {
// FormGenerator integration // FormGenerator integration
const snapshotYamlContent = () => cloneDeep(yamlContent.value ?? null) const snapshotYamlContent = () => cloneDeep(yamlContent.value ?? null)
// Build YAML without specific node // Build YAML without specific node (shallow clone path to avoid full deep-clone on editor open)
const buildYamlWithoutNode = (nodeId) => { const buildYamlWithoutNode = (nodeId) => {
const snapshot = snapshotYamlContent() const source = yamlContent.value
if (!snapshot?.graph?.nodes || !Array.isArray(snapshot.graph.nodes)) { if (!source?.graph?.nodes || !Array.isArray(source.graph.nodes)) {
return snapshot return source
}
return {
...source,
graph: {
...source.graph,
nodes: source.graph.nodes.filter(node => node?.id !== nodeId)
}
} }
snapshot.graph.nodes = snapshot.graph.nodes.filter(node => node?.id !== nodeId)
return snapshot
} }
const buildYamlWithoutEdge = (fromId, toId) => { const buildYamlWithoutEdge = (fromId, toId) => {
const snapshot = snapshotYamlContent() const source = yamlContent.value
if (!snapshot?.graph?.edges || !Array.isArray(snapshot.graph.edges)) { if (!source?.graph?.edges || !Array.isArray(source.graph.edges)) {
return snapshot return source
} }
let removed = false let removed = false
snapshot.graph.edges = snapshot.graph.edges.filter(edge => { const filteredEdges = source.graph.edges.filter(edge => {
if (!removed && edge?.from === fromId && edge?.to === toId) { if (!removed && edge?.from === fromId && edge?.to === toId) {
removed = true removed = true
return false return false
} }
return true return true
}) })
return snapshot return {
...source,
graph: {
...source.graph,
edges: filteredEdges
}
}
} }
const buildYamlWithoutVars = () => { const buildYamlWithoutVars = () => {
const snapshot = snapshotYamlContent() const source = yamlContent.value
if (!snapshot || typeof snapshot !== 'object') { if (!source || typeof source !== 'object') {
return snapshot return source
} }
if (!Object.prototype.hasOwnProperty.call(snapshot, 'vars')) { if (!Object.prototype.hasOwnProperty.call(source, 'vars')) {
return snapshot return source
} }
const sanitized = { ...snapshot } const sanitized = { ...source }
delete sanitized.vars delete sanitized.vars
return sanitized return sanitized
} }
const buildYamlWithoutMemory = () => { const buildYamlWithoutMemory = () => {
const snapshot = snapshotYamlContent() const source = yamlContent.value
if (!snapshot?.graph) { if (!source?.graph) {
return snapshot return source
} }
if (Object.prototype.hasOwnProperty.call(snapshot.graph, 'memory')) { if (Object.prototype.hasOwnProperty.call(source.graph, 'memory')) {
const newGraph = { ...snapshot.graph } const newGraph = { ...source.graph }
delete newGraph.memory delete newGraph.memory
snapshot.graph = newGraph return {
...source,
graph: newGraph
}
} }
return snapshot return source
} }
const buildYamlWithoutGraph = () => { const buildYamlWithoutGraph = () => {
const snapshot = snapshotYamlContent() const source = yamlContent.value
if (!snapshot || typeof snapshot !== 'object') { if (!source || typeof source !== 'object') {
return snapshot return source
} }
if (!Object.prototype.hasOwnProperty.call(snapshot, 'graph')) { if (!Object.prototype.hasOwnProperty.call(source, 'graph')) {
return snapshot return source
} }
const sanitized = { ...snapshot } const sanitized = { ...source }
delete sanitized.graph delete sanitized.graph
return sanitized return sanitized
} }
@ -1398,12 +1412,10 @@ const openDynamicFormGenerator = (type, options = {}) => {
const hasCustomYaml = Object.prototype.hasOwnProperty.call(options, 'initialYaml') const hasCustomYaml = Object.prototype.hasOwnProperty.call(options, 'initialYaml')
const yamlSource = hasCustomYaml ? options.initialYaml : yamlContent.value const yamlSource = hasCustomYaml ? options.initialYaml : yamlContent.value
formGeneratorInitialYaml.value = yamlSource ? cloneDeep(yamlSource) : null formGeneratorInitialYaml.value = yamlSource || null
if (Object.prototype.hasOwnProperty.call(options, 'initialFormData')) { if (Object.prototype.hasOwnProperty.call(options, 'initialFormData')) {
formGeneratorInitialFormData.value = options.initialFormData formGeneratorInitialFormData.value = options.initialFormData || null
? cloneDeep(options.initialFormData)
: null
} else { } else {
formGeneratorInitialFormData.value = null formGeneratorInitialFormData.value = null
} }