From 3df88df5836ab0b42e5c2e25a974132a295bb212 Mon Sep 17 00:00:00 2001 From: Vito Sansevero Date: Wed, 7 Oct 2026 18:46:16 -0700 Subject: [PATCH] fix: stop ComfyUI from loading the admin bundle into the canvas page WEB_DIRECTORY = "web" made ComfyUI inject every .js under web/ (admin.js, gallery.js, vendored Tailwind and ViewerJS) into the canvas page. The node extension moves to web/comfy/prompt_manager.js (content unchanged; its ../../scripts/app.js import resolves against the served URL, which is the same) and WEB_DIRECTORY points at that folder only. Admin and gallery assets are still served from web/ by the extension's own routes. tests/test_sort_contract.py still reads web/prompt_manager.js and must be updated to the new path by its owner. --- __init__.py | 6 ++- tests/test_extension_web_dir.py | 64 +++++++++++++++++++++++++++++++ web/{ => comfy}/prompt_manager.js | 0 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 tests/test_extension_web_dir.py rename web/{ => comfy}/prompt_manager.js (100%) diff --git a/__init__.py b/__init__.py index 43f608f..a0d3861 100644 --- a/__init__.py +++ b/__init__.py @@ -53,8 +53,10 @@ NODE_DISPLAY_NAME_MAPPINGS = { "PromptSearchList": "Prompt Search List", } -# Define path to web directory for UI components -WEB_DIRECTORY = "web" +# Canvas extension only. ComfyUI loads every .js under this directory into the +# canvas page, so the admin/gallery bundles and vendored libraries under web/ +# are served by our own routes instead (see py/api). +WEB_DIRECTORY = "web/comfy" # Add API routes (same pattern as ComfyUI_Assets) try: diff --git a/tests/test_extension_web_dir.py b/tests/test_extension_web_dir.py new file mode 100644 index 0000000..57f371f --- /dev/null +++ b/tests/test_extension_web_dir.py @@ -0,0 +1,64 @@ +"""ComfyUI loads only the canvas extension, not the admin or gallery bundles. + +ComfyUI serves every .js file under WEB_DIRECTORY into the canvas page, so the +directory must hold nothing but the node extension. +""" + +import os +import sys +import tempfile +import unittest + +TESTS_DIR = os.path.dirname(os.path.abspath(__file__)) +ROOT = os.path.dirname(TESTS_DIR) +sys.path.insert(0, ROOT) +sys.path.insert(0, TESTS_DIR) + +from test_init_package import load_package # noqa: E402 + + +class TestExtensionWebDir(unittest.TestCase): + package_name = "prompt_manager_pkg_web" + + @classmethod + def setUpClass(cls): + cls.tmp = tempfile.TemporaryDirectory() + output_dir = os.path.join(cls.tmp.name, "output") + os.makedirs(output_dir) + cls.package, _ = load_package( + cls.package_name, os.path.join(cls.tmp.name, "prompts.db"), output_dir + ) + + @classmethod + def tearDownClass(cls): + monitor = getattr(cls.package, "_global_image_monitor", None) + if monitor is not None: + monitor.stop_monitoring() + sys.modules.pop(cls.package_name, None) + cls.tmp.cleanup() + + def test_web_directory_is_the_canvas_extension_folder(self): + self.assertEqual(self.package.WEB_DIRECTORY, "web/comfy") + self.assertIn("WEB_DIRECTORY", self.package.__all__) + + def test_comfyui_resolves_the_folder_next_to_the_package(self): + # ComfyUI joins the module directory with WEB_DIRECTORY and checks isdir + folder = os.path.join(ROOT, self.package.WEB_DIRECTORY) + self.assertTrue(os.path.isdir(folder)) + self.assertEqual(sorted(os.listdir(folder)), ["prompt_manager.js"]) + + def test_extension_was_moved_not_copied(self): + self.assertFalse(os.path.exists(os.path.join(ROOT, "web", "prompt_manager.js"))) + + def test_extension_registers_with_the_canvas_app(self): + path = os.path.join(ROOT, "web", "comfy", "prompt_manager.js") + with open(path, encoding="utf-8") as f: + source = f.read() + self.assertIn("app.registerExtension(", source) + # Served at /extensions//prompt_manager.js, so ComfyUI's app module + # is two levels up regardless of where the file lives on disk. + self.assertIn('from "../../scripts/app.js"', source) + + +if __name__ == "__main__": + unittest.main() diff --git a/web/prompt_manager.js b/web/comfy/prompt_manager.js similarity index 100% rename from web/prompt_manager.js rename to web/comfy/prompt_manager.js