MMnode/web/js/editor-loader.js
Z User bac3101e4d fix: editor loader built a protocol-relative URL on standard installs
The base-prefix computation produced '//' when the loader is served
from the top-level /extensions mount (the standard case), turning the
editor import into '//<pack>/index.js'. Browsers parse that as a
protocol-relative URL and resolve '<pack>' as a DNS hostname, so the
editor entry never loaded: console shows 'Failed to load resource:
net::ERR_NAME_NOT_RESOLVED  moxie-multimedia/index.js' followed by
[vite:preloadError]. Only sub-path reverse-proxy deployments
accidentally worked. Base is now exactly '/' when there is no
sub-path prefix, and '<prefix>/' otherwise.
2026-09-29 04:57:25 +00:00

53 lines
2.5 KiB
JavaScript

// 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 "/<pack>/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/<pack>/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/<pack>/..." -> "/comfyui/"); the pack's own
// static mount sits at "<base><pack>/". 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 "<pack>" 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`);
}