jz Switch (lazy if/else)
Lazy if/else that mutes dead branches
- on_true
- on_false
- value
ComfyUI's stock switch nodes have a dirty secret: most of them evaluate both branches and just throw one away. When both branches are cheap that's fine. When one branch is a whole generation subgraph - a separate model pass, an upscale, an API call - you're burning time and tokens on work you then discard. jz Switch is the lazy if/else: a condition boolean picks on_true or on_false, and the branch you didn't pick never executes at all. It's an A/B routing valve (like the plumbing docs' "manual routing valve" shape), not a first-non-null fallback - that's its sibling jz Fallback's job.
The wildcard sockets accept anything - image, latent, string, model - so it routes whatever you need it to route. And because the sockets are *, you can even mix types: route an image when true and a string when false, if that's somehow what your graph needs.
The "output nothing" trick
Here's the feature that makes this node quietly powerful: both branches are optional. If the branch condition selected isn't connected, the node emits ComfyUI's ExecutionBlocker instead of a value, which silently skips everything downstream of it. That's how you build "if true, output the image; if false, output nothing" - no value at all flows, and downstream nodes simply don't run. The author's README spells the use case out: "if true output the image, else output nothing."
The lazy mechanism is the same one jz Fallback uses - the node asks the executor for only the branch it needs (on_true or on_false) via check_lazy_status, and checks the actual graph links so an unconnected socket isn't treated as a hard error. It's engine-correct lazy evaluation, not a hack.
The inputs that matter
- condition - a BOOLEAN, default
true. Wire it from any boolean source: a comparison node, a used_fallback output from jz Fallback, a widget. - on_true / on_false - the two candidates. Both optional, both wildcard.
The single output value is whatever branch won (or an ExecutionBlocker, which visually shows as nothing flowing).
Installing it
One pack, one clone:
cd ComfyUI/custom_nodes
git clone https://github.com/j-zhang19/comfyui-jz
Restart ComfyUI (or Manager → "comfyui-jz"), find it under jz/util. No models, no GPU, deps are just requests, pillow, numpy.
Common issues
The trap people hit with lazy switches in general: an unconnected selected branch silently mutes everything downstream, which can look like "nothing happened" if you expected the node to pass something through. If your graph just stops producing output, check whether the branch condition selected is actually wired. Also remember this is lazy, not magical - the downstream nodes of the unselected branch still need to be connected to something for the overall graph to be valid, they just won't run this pass. And if you want both branches evaluated and only one used (say, to warm a cache), this is the wrong tool - you want a plain A/B switch, not a lazy one.
Personal pack, solo author, zero community footprint: the README is the doc. For a node whose behavior is this well-defined, that's plenty.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| condition | BOOLEAN | true | — |
| on_trueopt | * | — | |
| on_falseopt | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| value | * | — |