-
Notifications
You must be signed in to change notification settings - Fork 3
Description
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 nodeCreated and getCustomWidgets function for extensions. When using waitForInit, the extension doesn't actually load until after the graph has already been created and nodeCreated will never be run. Similarly for getCustomWidgets, 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 app is available via import { app } from "../../scripts/app.js". I altered this slightly to import { 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:
/* shims.ts */
import { ComfyApp, ComfyApi } from '@comfyorg/comfyui-frontend-types'
// @ts-expect-error external file
import { app } from '/scripts/app.js'
// @ts-expect-error external file
import { api } from '/scripts/api.js'
declare const app: ComfyApp;
declare const api: ComfyApi;
export { app, api };Creating a dedicated file to do the imports is not necessary, but is convenient if app or api will 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.app I am open to alternative options, but this is what I have found works in my use case