Conversation
…ks and ensuring proper state management
…r layer placement
| async (_instance: ReactFlowInstance) => { | ||
| if (initialized) return; | ||
| if (!nodeId || nodeId === "") return; | ||
|
|
||
| instance.fitView({ | ||
| nodes: [ | ||
| { | ||
| id: nodeId ?? "", | ||
| }, | ||
| ], | ||
| duration: 500, | ||
| }); | ||
| focusNode(nodeId); | ||
| setInitialized(true); | ||
| }, | ||
| [nodeId, initialized], | ||
| [nodeId, initialized, focusNode], | ||
| ); | ||
|
|
||
| const [varsOpen, setVarsOpen] = useState(false); |
There was a problem hiding this comment.
Bug: focusNode's early return prevents setInitialized(true) if board.data is not loaded, causing node focus to fail silently.
Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
The initializeFlow callback calls focusNode(nodeId) which contains an early return if board.data?.nodes[nodeId] is not found. If board.data has not loaded when onInit fires, focusNode returns early, preventing setInitialized(true) from being called. Since onInit only fires once, the node will never be focused even after board.data loads, leading to a silent failure to focus the node on initial board load.
💡 Suggested Fix
Ensure setInitialized(true) is always called in initializeFlow regardless of focusNode's outcome, or implement a retry mechanism for focusNode after board.data loads.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: packages/ui/components/flow/flow-board.tsx#L370-L383
Potential issue: The `initializeFlow` callback calls `focusNode(nodeId)` which contains
an early return if `board.data?.nodes[nodeId]` is not found. If `board.data` has not
loaded when `onInit` fires, `focusNode` returns early, preventing `setInitialized(true)`
from being called. Since `onInit` only fires once, the node will never be focused even
after `board.data` loads, leading to a silent failure to focus the node on initial board
load.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 170916
This pull request introduces comprehensive support for layers (also called placeholders) in the flow copilot context and command system. It adds a new
LayerContextstructure, updates the graph context to include layers and their hierarchy, and extends all relevant copilot commands and tools to support placing, moving, and nesting nodes, placeholders, and comments within layers. Additionally, the UI is updated to streamline node focusing and propagate focus actions throughout components.Layer/Placeholder Support and Context Expansion
LayerContextstruct to represent layers/placeholder nodes, including hierarchy, pins, and contained node IDs, and integrated it into theGraphContextfor LLM context generation. [1] [2]LayerContextfor use in other modules.Copilot Command and Tool Extensions
target_layerfield to all relevant copilot commands (AddNode,AddPlaceholder,MoveNode,CreateComment,CreateLayer) to specify placement or nesting within a layer. [1] [2] [3] [4] [5]target_layerfor all applicable commands, with descriptions for LLM usage. [1] [2] [3] [4] [5]UI Improvements and Node Focusing
FlowBoardandFlowRunsComponentto centralize node focusing logic using thefocusNodefunction, removing redundant code and ensuring consistent node focus behavior across components. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]These changes collectively enable advanced process modeling workflows with nested layers, better LLM context, and improved user interactions in the flow UI.