feat: simplify paths

This commit is contained in:
2026-03-14 07:52:34 +01:00
parent 353c2db335
commit b642a7aab2
18 changed files with 541 additions and 506 deletions

View File

@@ -39,11 +39,10 @@ const DEFAULT_VIEWPORT_WIDTH = 1200
const DEFAULT_VIEWPORT_HEIGHT = 800
const RENDER_DEBOUNCE_MS = 250
/** Lifecycle state to pass to useSyncConnectionStatus so edge status (updating/paused/error) stays in sync. */
/** Lifecycle state to pass to useSyncConnectionStatus so edge status (updating/error) stays in sync. */
export type RenderingNodeLifecycle = {
updating: boolean
error: boolean
paused: boolean
}
export type RenderingNodeState = {
@@ -102,14 +101,21 @@ export function useRenderingNodeState(
data: RenderingNodeData | undefined
): RenderingNodeState {
const {
nodes,
edges,
nodes: contextNodes,
edges: contextEdges,
setNodes,
setEdges,
sourceIds: incomingIds,
updateData,
} = useAbstractNode<RenderingNodeData>(id, data ?? {})
// Subscribe to store graph so we re-render when any node/edge changes (e.g. ascendant data).
// Context only exposes a ref, so we wouldn't re-render when another node updates otherwise.
const storeNodes = useCanvasStore((s) => s.graph.nodes)
const storeEdges = useCanvasStore((s) => s.graph.edges)
const nodes = storeNodes.length > 0 ? storeNodes : contextNodes
const edges = storeEdges.length > 0 ? storeEdges : contextEdges
const nodesEdgesRef = useRef({ nodes, edges })
nodesEdgesRef.current = { nodes, edges }
@@ -189,8 +195,6 @@ export function useRenderingNodeState(
const lastManualRunTriggerRef = useRef(0)
const manualRunTriggerSyncedRef = useRef(false)
const triggerNodeIds = useCanvasStore((s) => s.path.triggerNodeIds)
const updateDataRef = useRef(updateData)
updateDataRef.current = updateData
const setNodesRef = useRef(setNodes)
@@ -200,13 +204,12 @@ export function useRenderingNodeState(
const hasPendingInputs =
effectiveUpdateMode === 'manual' &&
!loading &&
triggerNodeIds.length > 0 &&
incomingIds.length > 0 &&
sourceSignature !== lastRunSourceSignature
const lifecycle = useMemo<RenderingNodeLifecycle>(
() => ({ updating: loading, error: error != null, paused: hasPendingInputs }),
[loading, error, hasPendingInputs]
() => ({ updating: loading, error: error != null }),
[loading, error]
)
useSyncConnectionStatus(id, lifecycle)