mirror of
https://github.com/Comfy-Org/ComfyUI-React-Extension-Template.git
synced 2026-11-04 23:37:20 +00:00
[GH-ISSUE #14] Import app directly rather than waitForInit #7
Labels
No labels
help wanted
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/ComfyUI-React-Extension-Template#7
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mcmerdith on GitHub (Aug 1, 2025).
Original GitHub issue: https://github.com/Comfy-Org/ComfyUI-React-Extension-Template/issues/14
I just started developing a custom node using this template and ran into frustrating issues with the usage of
waitForInit.A prime example of this is the
nodeCreatedandgetCustomWidgetsfunction for extensions. When usingwaitForInit, the extension doesn't actually load until after the graph has already been created andnodeCreatedwill never be run. Similarly forgetCustomWidgets, the graph is created before the custom widgets are registered and do not display.This is fine for sidebar tabs, bottom panels, menus, etc, but altering the graph is not possible under this architecture (user is required to use
Fix node (recreate)for widgets defined by the extension to load correctly)The frontend docs specify that
appis available viaimport { app } from "../../scripts/app.js". I altered this slightly toimport { app } from "/scripts/app.js"which may not be strictly correct but it is working for me.In my extension I achieved this as follows:
Creating a dedicated file to do the imports is not necessary, but is convenient if
apporapiwill be used in multiple places and you want to avoid constantly redeclaring the type.My full (WIP) extension is prompt-legos to see this implementation in practice.
I am new to the comfy dev ecosystem, so if there is a specific reason to use
window.appI am open to alternative options, but this is what I have found works in my use case@christian-byrne commented on GitHub (Aug 1, 2025):
The template's
waitForInitfunction (main.tsx:20-52) waits forwindow.appto exist to avoid trying to mount things before the vue app is setup (if I recall correctly), but by then (as you identified):The current ComfyUI Extension Lifecycle is
init→ 2.addCustomNodeDefs→ 3.getCustomWidgets→ 4.beforeRegisterNodeDef→ 5.registerCustomNodes→ 6.beforeConfigureGraph→ 7.nodeCreated→ 8.loadedGraphNode→ 9.afterConfigureGraph→ 10.setupThe template currently registers at step 10, missing critical steps 3 and 7.
The
rewriteComfyImportsplugin (vite.config.ts:10-26) already supports direct imports:/scripts/app.js→http://127.0.0.1:8188/scripts/app.jsThis means your approach is already technically supported by the build system.
You are absolutely right. The template should support both patterns:
Both approaches can be used together in the same extension since the direct import and
window.appreference the same app instance - just accessed at different timing points during initialization. The template should be updated to demonstrate this hybrid approach with clear documentation on when to use each pattern.@mcmerdith commented on GitHub (Aug 1, 2025):
Okay, I can PR it, just wanted to check first to make sure I wasn't totally off base
@christian-byrne commented on GitHub (Aug 2, 2025):
Nope, you're right on the mark. Very much appreciated!