From f05735dcc0f0ea38794fc47163290bcfcf6f765f Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Tue, 24 Feb 2026 14:19:05 +0100 Subject: [PATCH] Fix refresh wiping all links when JSON file is missing When the file at json_path didn't exist, clicking Refresh Outputs returned empty keys causing all outputs and links to be removed. Now the API returns an error flag and the frontend bails out early, preserving existing outputs. Bump version to 1.2.1. Co-Authored-By: Claude Opus 4.6 --- json_loader_dynamic.py | 2 ++ pyproject.toml | 2 +- web/json_dynamic.js | 9 ++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/json_loader_dynamic.py b/json_loader_dynamic.py index e275735..8a10b02 100644 --- a/json_loader_dynamic.py +++ b/json_loader_dynamic.py @@ -63,6 +63,8 @@ if PromptServer is not None: seq = 1 data = read_json_data(json_path) target = get_batch_item(data, seq) + if not data: + return web.json_response({"keys": [], "types": [], "error": "file_not_found"}) keys = [] types = [] if isinstance(target, dict): diff --git a/pyproject.toml b/pyproject.toml index 1e5ab8a..499145a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "comfyui-json-dynamic" -version = "1.2.0" +version = "1.2.1" description = "ComfyUI nodes for dynamic JSON loading and string/path utility operations" license = { file = "LICENSE" } requires-python = ">=3.10" diff --git a/web/json_dynamic.js b/web/json_dynamic.js index 7073bba..df7b70a 100644 --- a/web/json_dynamic.js +++ b/web/json_dynamic.js @@ -39,7 +39,14 @@ app.registerExtension({ const resp = await api.fetchApi( `/json_dynamic/get_keys?path=${encodeURIComponent(pathWidget.value)}&sequence_number=${seqWidget?.value || 1}` ); - const { keys, types } = await resp.json(); + const data = await resp.json(); + const { keys, types } = data; + + // If the file wasn't found, keep existing outputs and links intact + if (data.error === "file_not_found") { + console.warn("[JSONDynamicLoader] File not found, keeping existing outputs:", pathWidget.value); + return; + } // Store keys and types in hidden widgets for persistence const okWidget = this.widgets?.find(w => w.name === "output_keys");