Files
CraftopiaStudio-ComfyUI-Cra…/js/smart_resize.js
T
rubz c6c26a35fa fix: read live node width in draw() instead of a stale LiteGraph cache; cache-bust shared module imports
- LiteGraph caches a widget's .width the first time it lays a custom-typed
  widget out and reuses that cached value on every later draw() call. For a
  divider/status/preset widget added before the node reaches its final size,
  that cached width goes stale and never updates, making section-divider
  lines and the status box stop partway across the node instead of spanning
  it, and clipping/unevenly sizing the preset chips. All three shared
  widgets now read node.size[0] directly in draw() instead of trusting the
  widgetWidth parameter, which sidesteps the stale cache entirely.
- Add a ?v=2 query string to every import of the shared/*.mjs modules.
  aiohttp's static file server doesn't send Cache-Control: no-store for
  these (unlike the top-level registered extension .js files), so browsers
  were free to keep serving an old cached copy even across a hard reload.
  A versioned import URL forces a fresh fetch regardless of cache state.
2026-08-13 16:29:25 +02:00

51 lines
2.1 KiB
JavaScript

import { app } from "../../scripts/app.js";
import { createPresetPickerWidget } from "./shared/preset_picker_widget.mjs?v=2";
import { isVueNodes } from "./shared/nodes2.mjs?v=2";
app.registerExtension({
name: "Craftopia.SmartResize",
async nodeCreated(node) {
if (node.comfyClass !== "SmartResize") return;
const longestSideWidget = node.widgets?.find(w => w.name === "longest_side");
if (!longestSideWidget) return;
const PRESETS = [512, 768, 1024, 1536];
const presetWidget = createPresetPickerWidget(node, longestSideWidget, PRESETS);
// Override serialize to exclude the non-serializable preset widget from
// widgets_values — same drift fix as SmartBatchResize (see that file for details).
const origSerialize = node.serialize;
node.serialize = function () {
const data = origSerialize.call(this);
if (data.widgets_values) {
data.widgets_values = this.widgets
.filter(w => w.serialize !== false && w.options?.serialize !== false)
.map(w => w.value);
}
return data;
};
// Move preset row to right after longest_side — classic mode only.
// Under Nodes 2.0, splicing the DOM widget into the middle of
// node.widgets after configure() has already run desyncs Vue's
// value-to-row binding for every widget after it (see the comment in
// smart_batch_resize.js for the full explanation).
if (!isVueNodes()) {
const lsIdx = node.widgets.indexOf(longestSideWidget);
const pwIdx = node.widgets.indexOf(presetWidget);
if (pwIdx !== lsIdx + 1) {
node.widgets.splice(pwIdx, 1);
node.widgets.splice(lsIdx + 1, 0, presetWidget);
}
}
// Force a full size/layout recompute now that the preset widget has
// been added and repositioned — see the comment in
// smart_batch_resize.js for why this is needed.
node.setSize(node.computeSize());
node.setDirtyCanvas(true, true);
},
});