Skip to content

fix(ui): action selector hydration race#2557

Merged
daryllimyt merged 2 commits intomainfrom
fix/first-selector
Apr 23, 2026
Merged

fix(ui): action selector hydration race#2557
daryllimyt merged 2 commits intomainfrom
fix/first-selector

Conversation

@daryllimyt
Copy link
Copy Markdown
Contributor

@daryllimyt daryllimyt commented Apr 23, 2026

Summary

  • Preserve local-only selector nodes and temporary selector edges when backend graph hydration/refetches run.
  • Keep canvas nodes and edges in one state object so hydration uses the latest queued graph state without ref-synced effects.
  • Optimize the selector action list by sorting/filtering once and skipping fuzzysort for the initial empty query.

Root Cause

The action selector is an ephemeral React Flow node that is not persisted in the backend graph. When the first graph hydration/refetch completed after a drag, the canvas replaced local nodes/edges with only the hydrated backend graph, dropping the just-created selector.

Validation

  • pnpm -C frontend exec biome check --write src/components/builder/canvas/canvas.tsx src/components/builder/canvas/graph-layout.ts tests/graph-layout.test.ts
  • pnpm -C frontend test -- graph-layout.test.ts
  • pnpm -C frontend exec biome check --write src/components/builder/canvas/selector-node.tsx
  • pnpm -C frontend run typecheck
  • uv run ruff check .
  • git diff --check

Summary by cubic

Fixes a race that removed the action selector after the first graph hydration by preserving ephemeral nodes/edges and updating canvas state handling. Also speeds up selector filtering for a snappier first keystroke.

  • Bug Fixes

    • Preserve local-only selector nodes and their temporary edges during backend hydration/refetch by merging hydrated data with ephemeral elements.
    • Reset ephemeral elements when switching workflows to avoid leaking state.
    • Use applyNodeChanges/applyEdgeChanges from @xyflow/react with unified state to avoid stale updates.
  • Refactors

    • Keep canvas nodes and edges in a single state object; add mergeHydratedNodes/mergeHydratedEdges with optional ephemeral preservation.
    • Optimize selector filtering: pre-sort actions, skip fuzzysort for empty queries, and compute results once per input.
    • Add tests for node/edge merge behavior with ephemeral nodes.

Written for commit 8f65f0f. Summary will update on new commits.

@daryllimyt daryllimyt marked this pull request as ready for review April 23, 2026 03:05
@daryllimyt daryllimyt changed the title [codex] Fix action selector hydration race fix(ui): action selector hydration race Apr 23, 2026
@zeropath-ai
Copy link
Copy Markdown

zeropath-ai Bot commented Apr 23, 2026

No security or compliance issues detected. Reviewed everything up to 8f65f0f.

Security Overview
Detected Code Changes
Change Type Relevant files
Refactor ► frontend/src/components/builder/canvas/canvas.tsx
    Refactor state management for nodes and edges
    Introduce CanvasGraphState and resolveStateAction
    Implement removeEphemeralGraphElements function
    Update setNodes and setEdges callbacks
    Modify onNodesChange and onEdgesChange implementations
    Introduce hydrateCanvasFromGraph function
    Update useEffect hook for workflowId
    Adjust useEffect for fetching graph data
    Refactor handleNodesChange implementation
► frontend/src/components/builder/canvas/graph-layout.ts
    Add HydratedGraphMergeOptions interface
    Modify mergeHydratedNodes to accept options
    Implement mergeHydratedEdges function
► frontend/src/components/builder/canvas/selector-node.tsx
    Refactor filterActions to return ActionFilterResult
    Move sorting and filtering logic into useMemo hooks
    Update ActionCommandGroup props
► frontend/tests/graph-layout.test.ts
    Add tests for ephemeral node preservation in mergeHydratedNodes
    Add tests for edge preservation and hydrated list usage in mergeHydratedEdges

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

@daryllimyt daryllimyt merged commit cf38e1c into main Apr 23, 2026
11 checks passed
@daryllimyt daryllimyt deleted the fix/first-selector branch April 23, 2026 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant