From f94bdc358bb5053bd6763a91b07e24b1f3701481 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Wed, 9 Oct 2024 16:02:27 -0400 Subject: [PATCH] Disable node def validation by default (#1190) * Add setting * Make node def validation optional --- src/scripts/api.ts | 8 +++++++- src/scripts/app.ts | 8 ++++++-- src/stores/coreSettings.ts | 9 +++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/scripts/api.ts b/src/scripts/api.ts index 30a35dcf5..cfde56b61 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -273,9 +273,15 @@ class ComfyApi extends EventTarget { * Loads node object definitions for the graph * @returns The node definitions */ - async getNodeDefs(): Promise> { + async getNodeDefs({ validate = false }: { validate?: boolean } = {}): Promise< + Record + > { const resp = await this.fetchApi('/object_info', { cache: 'no-store' }) const objectInfoUnsafe = await resp.json() + if (!validate) { + return objectInfoUnsafe + } + // Validate node definitions against zod schema. (slow) const objectInfo: Record = {} for (const key in objectInfoUnsafe) { const validatedDef = validateComfyNodeDef( diff --git a/src/scripts/app.ts b/src/scripts/app.ts index 11a3b4a8c..858cc7a48 100644 --- a/src/scripts/app.ts +++ b/src/scripts/app.ts @@ -1968,7 +1968,9 @@ export class ComfyApp { */ async registerNodes() { // Load node definitions from the backend - const defs = await api.getNodeDefs() + const defs = await api.getNodeDefs({ + validate: useSettingStore().get('Comfy.Validation.NodeDefs') + }) await this.registerNodesFromDefs(defs) await this.#invokeExtensionsAsync('registerCustomNodes') if (this.vueAppReady) { @@ -2911,7 +2913,9 @@ export class ComfyApp { useModelStore().clearCache() } - const defs = await api.getNodeDefs() + const defs = await api.getNodeDefs({ + validate: useSettingStore().get('Comfy.Validation.NodeDefs') + }) for (const nodeId in defs) { this.registerNodeDef(nodeId, defs[nodeId]) diff --git a/src/stores/coreSettings.ts b/src/stores/coreSettings.ts index 72ad7f558..99b758189 100644 --- a/src/stores/coreSettings.ts +++ b/src/stores/coreSettings.ts @@ -435,5 +435,14 @@ export const CORE_SETTINGS: SettingParams[] = [ defaultValue: false, experimental: true, versionAdded: '1.3.11' + }, + { + id: 'Comfy.Validation.NodeDefs', + name: 'Validate node definitions (slow)', + type: 'boolean', + tooltip: + 'Recommended for node developers. This will validate all node definitions on startup.', + defaultValue: false, + versionAdded: '1.3.14' } ]