jz Fallback (lazy if/else)
The branch that only runs when it has to
- primary
- fallback
- value
- used_fallback
The classic ComfyUI workflow problem: "use the image I uploaded, and if there isn't one, generate one." Naive versions of that graph don't work, because ComfyUI evaluates the whole graph - the generator runs even when you don't need it, wasting time and tokens. jz Fallback is the lazy version: it passes primary through when a value arrives, and only evaluates fallback when primary is absent. The branch you don't use never executes.
That "never executes" is the whole point, and it's what separates this from a dumb first-non-null node. The unused branch isn't skipped after running - the graph executor is told not to evaluate it at all, via ComfyUI's lazy-evaluation hook (check_lazy_status). So you can hang an expensive generation subgraph off fallback and a simple uploaded image off primary, and a workflow that "has an image" costs almost nothing, while a workflow with no image automatically runs the generator. Same idea as a first-non-null fallback like rgthree's Any Switch, but with real laziness instead of "run everything, keep the first non-null."
How it works
Two wildcard inputs - primary and fallback - and since they're * type, they accept an image, a latent, a string, a model, anything. The node's lazy hook only requests fallback from the executor when primary arrives as None. Then:
primarypresent → outputs it, and theused_fallbackBOOLEAN isfalse.primaryabsent,fallbackpresent → outputsfallback, andused_fallbackistrue.- both absent → the node raises, telling you to connect at least one input. (It won't even request an unconnected
fallbacksocket, which would be a hard executor error.)
The used_fallback output is the sleeper feature. Wire it into a jz Switch or any boolean consumer and the rest of the graph can react to which branch fired - e.g. skip a save step when the fallback ran, or log that the image was AI-generated rather than uploaded.
The classic wiring
The author's own suggested setup is the most useful one: primary = an optional uploaded image, fallback = the generation subgraph. Wrap the generator's output into fallback, drop the uploaded image into primary, and downstream you have "one image, source unknown." It also composes beautifully with jz Switch, which is the boolean-driven cousin in the same pack: Fallback decides whether something exists, Switch decides which of two things to take.
Installing it
It's in the comfyui-jz pack:
cd ComfyUI/custom_nodes
git clone https://github.com/j-zhang19/comfyui-jz
Restart ComfyUI, or use ComfyUI Manager and search for "comfyui-jz." Find it under jz/util. Dependencies are minimal - requests, pillow, numpy - no models, no GPU.
Common issues
The one real footgun is expecting a value to be "present" when it's actually an empty/zero thing. Lazy evaluation keys off None - an empty string or a zero image is still a value, so primary "wins" and you get an empty result instead of the fallback. If your upstream can emit empty values, filter them before this node. Otherwise the behavior is refreshingly simple: connect one side, connect the other, done.
Personal-pack caveat as always: solo author, no community footprint, README as documentation. For a node this small and predictable, you won't miss more.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| primaryopt | * | — | |
| fallbackopt | * | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| value | * | — |
| used_fallback | BOOLEAN | — |