File size: 2,563 Bytes
3c2af96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4808224
 
 
 
 
 
3c2af96
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// 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`);
}