mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-12 00:20:15 +00:00
Documents the distinction between `widget.serialize` (workflow persistence, checked by `LGraphNode.serialize()`) and `widget.options.serialize` (API prompt, checked by `executionUtil.ts`). These share a property name but live at different levels of the widget object and are consumed by different code paths — a common source of confusion when debugging serialization bugs. Includes: - Explanation of both properties with code references - Permutation table of the 4 possible combinations with real examples - Gotchas section covering the `addWidget` options bag behavior and `PrimitiveNode` dynamic widgets - Reference added to `src/lib/litegraph/AGENTS.md` Context: discovered while debugging #1757 (PrimitiveNode `control_after_generate` lost on copy-paste). ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-9102-docs-add-widget-serialization-reference-widget-serialize-vs-widget-options-serialize-30f6d73d365081cd86add44bdaa20d30) by [Unito](https://www.unito.io) --------- Co-authored-by: GitHub Action <action@github.com>
1.7 KiB
1.7 KiB
Litegraph Guidelines
Code Philosophy
- Write concise, legible, and easily maintainable code
- Avoid repetition where possible, but not at expense of legibility
- Prefer running single tests, not the whole suite, for performance
Widget Serialization
See docs/WIDGET_SERIALIZATION.md for the distinction between widget.serialize (workflow persistence) and widget.options.serialize (API prompt). These are different properties checked by different code paths — a common source of confusion.
Code Style
- Prefer single line
ifsyntax for concise expressions - Take advantage of
TypedArraysubarraywhen appropriate - The
sizeandposproperties ofRectangleshare the same array buffer - Prefer returning
undefinedovernull - Type assertions are a last resort (acceptable for legacy code interop)
Circular Dependencies in Tests
CRITICAL: Always import from the barrel export for subgraph code:
// ✅ Correct - barrel import
import { LGraph, Subgraph, SubgraphNode } from '@/lib/litegraph/src/litegraph'
// ❌ Wrong - causes circular dependency
import { LGraph } from '@/lib/litegraph/src/LGraph'
Root cause: LGraph ↔ Subgraph circular dependency (Subgraph extends LGraph, LGraph creates Subgraph instances).
Known Limitations
- Subgraph dynamic input limitations (autogrow/matchtype): see
src/core/graph/subgraph-dynamic-input-limitations.md
Test Helpers
import {
createTestSubgraph,
createTestSubgraphNode
} from './__fixtures__/subgraphHelpers'
function createTestSetup() {
const subgraph = createTestSubgraph()
const subgraphNode = createTestSubgraphNode(subgraph)
return { subgraph, subgraphNode }
}