fix: a field left open on a swapped-away node drops its value and says so

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
digital-garbage
2026-10-06 12:25:17 +03:00
co-authored by Claude Opus 5.5
parent feabbaaa4b
commit d65014b135
2 changed files with 22 additions and 0 deletions
+1
View File
@@ -49,6 +49,7 @@ export const models = (app) => function mount() {
}
const setInput = (slot, name) => async (value) => {
const live = slotsNow().find((x) => x.id === slot.id) || slot; // the slot as it is now, not as drawn: an answer may have replaced it
if (live.node !== slot.node) return say(`That field belonged to ${slot.node}, which was swapped for ${live.node}: the value was not kept.`);
if (JSON.stringify((live.inputs || {})[name]) === JSON.stringify(value)) return; // a blur that changed nothing saves nothing
await ps.save({ inputs: { [slot.id]: { [name]: value } } });
say([...(ps.refused() || []), ...ps.saveNotes()].join(" "));
+21
View File
@@ -80,3 +80,24 @@ test("a problem that names no slot first (a loop) still shows its nodes in the s
assert.match(page.node.textContent, /cannot end up feeding itself/);
page.node.remove();
});
test("a field still on screen for a node that was swapped away does not put its value on the new node", async () => {
let slots = [{ id: "k", node: "FunPackSampler", inputs: { steps: 8 } }];
const saved = [];
const ps = { slots: () => slots, snapshot: () => ({ slots }), ensureLoaded: async () => {}, subscribe: () => () => {}, restore: async () => ({ refused: [] }),
save: async (b) => { saved.push(b); }, loading: () => false, loadError: () => null, saveNotes: () => [], incomplete: () => [], refused: () => [],
queueable: () => true, removedIds: () => [], offered: () => [] };
const nodes = { FunPackSampler: { widgets: [{ name: "steps", type: "INT", min: 1, max: 100 }] }, Other: { widgets: [] } };
const page = models({ pipeline: ps, api: { describeNodes: async () => ({ nodes }), packProviders: async () => ({}) } })();
document.body.append(page.node);
await new Promise((r) => setTimeout(r, 0));
page.node.querySelector(".fp-node-card").click(); // open it
const field = page.node.querySelector("input[type=number]");
slots = [{ id: "k", node: "Other", inputs: {} }]; // the swap's answer lands; the field stays
field.value = "20";
field.dispatchEvent(new window.Event("change", { bubbles: true }));
await new Promise((r) => setTimeout(r, 0));
assert.deepEqual(saved, []);
assert.match(page.node.textContent, /was swapped for Other: the value was not kept/);
page.node.remove();
});