[Refactor] Use util.clone in mergeIfValid (#2752)

This commit is contained in:
Chenlei Hu
2025-02-27 11:47:56 -05:00
committed by GitHub
parent f9157ee05f
commit 96f02dbf80
2 changed files with 3 additions and 7 deletions

View File

@@ -13,7 +13,7 @@ import type {
import type { CanvasMouseEvent } from '@comfyorg/litegraph/dist/types/events'
import { app } from '@/scripts/app'
import { applyTextReplacements } from '@/scripts/utils'
import { applyTextReplacements, clone } from '@/scripts/utils'
import { ComfyWidgets, addValueControlWidgets } from '@/scripts/widgets'
import { useNodeDefStore } from '@/stores/nodeDefStore'
import { useSettingStore } from '@/stores/settingStore'
@@ -647,11 +647,7 @@ export function mergeIfValid(
let customConfig: Record<string, unknown> | undefined
const getCustomConfig = () => {
if (!customConfig) {
if (typeof structuredClone === 'undefined') {
customConfig = JSON.parse(JSON.stringify(config1[1] ?? {}))
} else {
customConfig = structuredClone(config1[1] ?? {})
}
customConfig = clone(config1[1] ?? {})
}
return customConfig
}

View File

@@ -28,7 +28,7 @@ function formatDate(text: string, date: Date) {
})
}
export function clone(obj: any) {
export function clone<T>(obj: T): T {
try {
if (typeof structuredClone !== 'undefined') {
return structuredClone(obj)