From 312cbaf0cb418cfdcc8fa1e9adbeaad72dd18f7b Mon Sep 17 00:00:00 2001 From: Immac Date: Mon, 2 Mar 2026 09:46:14 -0600 Subject: [PATCH] fix: skip setSizeForImage when clearing preview to preserve widget callback --- dist/immac_style_mixer/main.js | 4 ++-- ui/src/main.tsx | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/dist/immac_style_mixer/main.js b/dist/immac_style_mixer/main.js index b0d2632..6852663 100644 --- a/dist/immac_style_mixer/main.js +++ b/dist/immac_style_mixer/main.js @@ -1,5 +1,5 @@ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["immac_style_mixer/StyleMixerPanel-SEpYmuEo.js","immac_style_mixer/vendor-DPfS0z4g.js"])))=>i.map(i=>d[i]); -import{r as P,a as O,R as C}from"./vendor-DPfS0z4g.js";const L="modulepreload",M=function(t){return"/"+t},b={},U=function(e,l,i){let m=Promise.resolve();if(l&&l.length>0){document.getElementsByTagName("link");const r=document.querySelector("meta[property=csp-nonce]"),n=(r==null?void 0:r.nonce)||(r==null?void 0:r.getAttribute("nonce"));m=Promise.allSettled(l.map(o=>{if(o=M(o),o in b)return;b[o]=!0;const a=o.endsWith(".css"),p=a?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${o}"]${p}`))return;const c=document.createElement("link");if(c.rel=a?"stylesheet":L,a||(c.as="script"),c.crossOrigin="",c.href=o,n&&c.setAttribute("nonce",n),document.head.appendChild(c),a)return new Promise((y,w)=>{c.addEventListener("load",y),c.addEventListener("error",()=>w(new Error(`Unable to preload CSS for ${o}`)))})}))}function u(r){const n=new Event("vite:preloadError",{cancelable:!0});if(n.payload=r,window.dispatchEvent(n),!n.defaultPrevented)throw r}return m.then(r=>{for(const n of r||[])n.status==="rejected"&&u(n.reason);return e().catch(u)})};var k={exports:{}},g={};/** +import{r as R,a as j,R as P}from"./vendor-DPfS0z4g.js";const O="modulepreload",L=function(t){return"/"+t},I={},M=function(e,l,i){let m=Promise.resolve();if(l&&l.length>0){document.getElementsByTagName("link");const r=document.querySelector("meta[property=csp-nonce]"),n=(r==null?void 0:r.nonce)||(r==null?void 0:r.getAttribute("nonce"));m=Promise.allSettled(l.map(o=>{if(o=L(o),o in I)return;I[o]=!0;const a=o.endsWith(".css"),p=a?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${o}"]${p}`))return;const c=document.createElement("link");if(c.rel=a?"stylesheet":O,a||(c.as="script"),c.crossOrigin="",c.href=o,n&&c.setAttribute("nonce",n),document.head.appendChild(c),a)return new Promise((y,w)=>{c.addEventListener("load",y),c.addEventListener("error",()=>w(new Error(`Unable to preload CSS for ${o}`)))})}))}function d(r){const n=new Event("vite:preloadError",{cancelable:!0});if(n.payload=r,window.dispatchEvent(n),!n.defaultPrevented)throw r}return m.then(r=>{for(const n of r||[])n.status==="rejected"&&d(n.reason);return e().catch(d)})};var C={exports:{}},g={};/** * @license React * react-jsx-runtime.production.min.js * @@ -7,4 +7,4 @@ import{r as P,a as O,R as C}from"./vendor-DPfS0z4g.js";const L="modulepreload",M * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var T=P,$=Symbol.for("react.element"),D=Symbol.for("react.fragment"),F=Object.prototype.hasOwnProperty,A=T.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,q={key:!0,ref:!0,__self:!0,__source:!0};function j(t,e,l){var i,m={},u=null,r=null;l!==void 0&&(u=""+l),e.key!==void 0&&(u=""+e.key),e.ref!==void 0&&(r=e.ref);for(i in e)F.call(e,i)&&!q.hasOwnProperty(i)&&(m[i]=e[i]);if(t&&t.defaultProps)for(i in e=t.defaultProps,e)m[i]===void 0&&(m[i]=e[i]);return{$$typeof:$,type:t,key:u,ref:r,props:m,_owner:A.current}}g.Fragment=D;g.jsx=j;g.jsxs=j;k.exports=g;var h=k.exports,x={},R=O;x.createRoot=R.createRoot,x.hydrateRoot=R.hydrateRoot;const z=C.lazy(()=>U(()=>import("./StyleMixerPanel-SEpYmuEo.js"),__vite__mapDeps([0,1])));function B(){return new Promise(t=>{function e(){if(window.app){t();return}const l=setInterval(()=>{window.app&&(clearInterval(l),t())},50);setTimeout(()=>{clearInterval(l),console.error("[ImmacStyleMixer] Timeout waiting for ComfyUI app"),t()},5e3)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e):e()})}async function W(){if(await B(),!window.app){console.error("[ImmacStyleMixer] ComfyUI app not available");return}window.app.extensionManager.registerSidebarTab({id:"immac-style-mixer",icon:"pi pi-palette",title:"Style Mixer",tooltip:"Immac Style Mixer",type:"custom",render:t=>{const e=document.createElement("div");e.id="immac-style-mixer-root",e.style.position="absolute",e.style.inset="0",e.style.overflow="hidden",t.style.position="relative",t.style.height="100%",t.appendChild(e),x.createRoot(e).render(h.jsx(C.StrictMode,{children:h.jsx(P.Suspense,{fallback:h.jsx("div",{style:{padding:"1rem"},children:"Loading…"}),children:h.jsx(z,{})})}))}}),window.app.registerExtension({name:"ImmacStyleMixer",nodeCreated(t){var u;if(t.comfyClass!=="StyleMixImmacStyleMixer")return;const e=(u=t.widgets)==null?void 0:u.find(r=>r.name==="mix");if(!e)return;function l(r){return new Promise((n,o)=>{const a=new Image;a.onload=()=>n(a),a.onerror=o,a.src=r})}async function i(r){var n,o,a,p,c,y,w,S;try{const v=await fetch("/immac_style_mixer/api/data");if(!v.ok)return;const E=await v.json(),d=(n=E.mixes)==null?void 0:n.find(f=>f.name===r);let _=[];if(d!=null&&d.image_filename)_=[`/view?filename=${encodeURIComponent(d.image_filename)}&subfolder=immac_style_mixer%2Fmixes&type=input`];else if((o=d==null?void 0:d.styles)!=null&&o.length){const f=Object.fromEntries((E.styles??[]).map(s=>[s.id,s]));_=d.styles.filter(s=>s.enabled!==!1).map(s=>f[s.style_id]).filter(s=>s==null?void 0:s.image_filename).map(s=>`/view?filename=${encodeURIComponent(s.image_filename)}&subfolder=immac_style_mixer%2Fstyles&type=input`)}if(!_.length){t.imgs=void 0,(a=t.setSizeForImage)==null||a.call(t),(c=(p=window.app)==null?void 0:p.graph)==null||c.setDirtyCanvas(!0);return}const I=(await Promise.allSettled(_.map(l))).flatMap(f=>f.status==="fulfilled"?[f.value]:[]);t.imgs=I.length?I:void 0,(y=t.setSizeForImage)==null||y.call(t),(S=(w=window.app)==null?void 0:w.graph)==null||S.setDirtyCanvas(!0)}catch(v){console.error("[ImmacStyleMixer] Preview update failed",v)}}const m=e.callback;e.callback=function(r){m&&m.call(this,r),i(r)},e.value&&i(e.value)}})}W().catch(console.error);export{h as j}; + */var U=R,T=Symbol.for("react.element"),$=Symbol.for("react.fragment"),D=Object.prototype.hasOwnProperty,F=U.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,A={key:!0,ref:!0,__self:!0,__source:!0};function k(t,e,l){var i,m={},d=null,r=null;l!==void 0&&(d=""+l),e.key!==void 0&&(d=""+e.key),e.ref!==void 0&&(r=e.ref);for(i in e)D.call(e,i)&&!A.hasOwnProperty(i)&&(m[i]=e[i]);if(t&&t.defaultProps)for(i in e=t.defaultProps,e)m[i]===void 0&&(m[i]=e[i]);return{$$typeof:T,type:t,key:d,ref:r,props:m,_owner:F.current}}g.Fragment=$;g.jsx=k;g.jsxs=k;C.exports=g;var h=C.exports,x={},b=j;x.createRoot=b.createRoot,x.hydrateRoot=b.hydrateRoot;const q=P.lazy(()=>M(()=>import("./StyleMixerPanel-SEpYmuEo.js"),__vite__mapDeps([0,1])));function B(){return new Promise(t=>{function e(){if(window.app){t();return}const l=setInterval(()=>{window.app&&(clearInterval(l),t())},50);setTimeout(()=>{clearInterval(l),console.error("[ImmacStyleMixer] Timeout waiting for ComfyUI app"),t()},5e3)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e):e()})}async function W(){if(await B(),!window.app){console.error("[ImmacStyleMixer] ComfyUI app not available");return}window.app.extensionManager.registerSidebarTab({id:"immac-style-mixer",icon:"pi pi-palette",title:"Style Mixer",tooltip:"Immac Style Mixer",type:"custom",render:t=>{const e=document.createElement("div");e.id="immac-style-mixer-root",e.style.position="absolute",e.style.inset="0",e.style.overflow="hidden",t.style.position="relative",t.style.height="100%",t.appendChild(e),x.createRoot(e).render(h.jsx(P.StrictMode,{children:h.jsx(R.Suspense,{fallback:h.jsx("div",{style:{padding:"1rem"},children:"Loading…"}),children:h.jsx(q,{})})}))}}),window.app.registerExtension({name:"ImmacStyleMixer",nodeCreated(t){var d;if(t.comfyClass!=="StyleMixImmacStyleMixer")return;const e=(d=t.widgets)==null?void 0:d.find(r=>r.name==="mix");if(!e)return;function l(r){return new Promise((n,o)=>{const a=new Image;a.onload=()=>n(a),a.onerror=o,a.src=r})}async function i(r){var n,o,a,p,c,y,w;try{const v=await fetch("/immac_style_mixer/api/data");if(!v.ok)return;const S=await v.json(),u=(n=S.mixes)==null?void 0:n.find(f=>f.name===r);let _=[];if(u!=null&&u.image_filename)_=[`/view?filename=${encodeURIComponent(u.image_filename)}&subfolder=immac_style_mixer%2Fmixes&type=input`];else if((o=u==null?void 0:u.styles)!=null&&o.length){const f=Object.fromEntries((S.styles??[]).map(s=>[s.id,s]));_=u.styles.filter(s=>s.enabled!==!1).map(s=>f[s.style_id]).filter(s=>s==null?void 0:s.image_filename).map(s=>`/view?filename=${encodeURIComponent(s.image_filename)}&subfolder=immac_style_mixer%2Fstyles&type=input`)}if(!_.length){t.imgs=void 0,(p=(a=window.app)==null?void 0:a.graph)==null||p.setDirtyCanvas(!0);return}const E=(await Promise.allSettled(_.map(l))).flatMap(f=>f.status==="fulfilled"?[f.value]:[]);E.length?(t.imgs=E,(c=t.setSizeForImage)==null||c.call(t)):t.imgs=void 0,(w=(y=window.app)==null?void 0:y.graph)==null||w.setDirtyCanvas(!0)}catch(v){console.error("[ImmacStyleMixer] Preview update failed",v)}}const m=e.callback;e.callback=function(r){m&&m.call(this,r),i(r)},e.value&&i(e.value)}})}W().catch(console.error);export{h as j}; diff --git a/ui/src/main.tsx b/ui/src/main.tsx index 8ddeac1..c58711c 100644 --- a/ui/src/main.tsx +++ b/ui/src/main.tsx @@ -113,15 +113,18 @@ async function init(): Promise { if (!urls.length) { node.imgs = undefined - node.setSizeForImage?.() window.app?.graph?.setDirtyCanvas(true) return } const results = await Promise.allSettled(urls.map(loadImage)) const loaded = results.flatMap((r) => (r.status === 'fulfilled' ? [r.value] : [])) - node.imgs = loaded.length ? loaded : undefined - node.setSizeForImage?.() + if (loaded.length) { + node.imgs = loaded + node.setSizeForImage?.() + } else { + node.imgs = undefined + } window.app?.graph?.setDirtyCanvas(true) } catch (e) { console.error('[ImmacStyleMixer] Preview update failed', e)