// Editor bundle loader. // // WHY THIS FILE EXISTS // ComfyUI core (nodes.py, load_custom_node) lets a pack's WEB_DIRECTORY // overwrite its EXTENSION_WEB_DIRS entry after the pack's __init__.py has // run. This pack ships WEB_DIRECTORY = "./web" (the helper files next to // this loader), so core's static mount and the browser's /extensions listing // only ever see THIS directory - never dist/release. The React editor entry // (dist/release/index.js) would therefore never be imported on a fresh // browser, and the editor only appeared for people whose browser still held // an old cached copy. // // This loader bridges that gap: the frontend imports every listed extension // file (this one included), and this file then imports the real editor entry // from the pack's own static mount "//index.js", which __init__.py // serves with "Cache-Control: no-cache, must-revalidate". The entry file is // therefore always revalidated, and its relative chunk imports // ("./chunks/...") resolve against the same mount, which serves the // content-hashed chunk files that ship next to it. No cache can pin a stale // editor bundle anymore. // // The pack folder name is derived from this file's own URL // (.../extensions//js/editor-loader.js), so the loader works no matter // what the pack directory is called. const segments = new URL(import.meta.url).pathname .split('/') .filter(Boolean) .map(decodeURIComponent); const extensionsIndex = segments.lastIndexOf('extensions'); const packName = extensionsIndex >= 0 ? segments[extensionsIndex + 1] : null; if (!packName) { console.warn( '[Moxie Multimedia Suite] editor loader could not resolve the pack folder from', import.meta.url, ); } else { // Base prefix covers deployments behind a sub-path reverse proxy // ("/comfyui/extensions//..." -> "/comfyui/"); the pack's own // static mount sits at "/". For the standard deployment // there is no prefix and base is exactly "/" - it must NEVER be "//", // which the browser would parse as a protocol-relative URL and try to // resolve "" as a DNS hostname (net::ERR_NAME_NOT_RESOLVED). const prefix = segments.slice(0, extensionsIndex); const base = prefix.length ? '/' + prefix.join('/') + '/' : '/'; // Top-level await: extension scripts are awaited before ComfyUI registers // node definitions, so the editor's registerExtension()/custom-widget // hooks stay in the normal loading order. await import(`${base}${packName}/index.js`); }