Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • remove more remaining manual state management and refetching in favor of reactquery
  • removed unnecessary lightweight wrappers that are only used in one place

Type of Change

  • Bug fix

Testing

N/A

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Jan 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 16, 2026 7:57pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 16, 2026

Greptile Summary

Replaced manual state management and refetching with React Query patterns for child workflow deployments and schedule info. Removed two lightweight wrapper hooks (use-child-deployment.ts and use-schedule-info.ts) that were only used in one location each, consolidating all query logic into centralized query files (workflows.ts and schedules.ts). The new useChildDeploymentStatus query and useDeployChildWorkflow mutation properly handle cache invalidation automatically through React Query's mutation callbacks, eliminating the need for manual refetch() calls throughout the codebase.

Key improvements:

  • Removed manual useState, useEffect, and fetch logic from component-level hooks
  • Centralized all workflow deployment queries in apps/sim/hooks/queries/workflows.ts
  • Eliminated redundant refetchServers() calls in MCP deploy component (mutations already invalidate cache)
  • Simplified useChildWorkflow hook by removing manual refetch function
  • Consistent React Query patterns with proper staleTime (30s) and cache invalidation

Confidence Score: 5/5

  • Safe to merge with no issues found
  • The refactoring follows React Query best practices and properly handles cache invalidation through mutation callbacks. All manual refetch calls were correctly removed since the mutations already invalidate the relevant query keys. The migration from manual state management to React Query improves code maintainability and reduces potential bugs from stale data.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/hooks/queries/workflows.ts Added useChildDeploymentStatus query and useDeployChildWorkflow mutation with proper cache invalidation
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/hooks/use-child-deployment.ts Removed lightweight wrapper hook, replaced by React Query hooks in workflows.ts
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/hooks/use-schedule-info.ts Removed unnecessary wrapper hook that was only used in one location
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/workflow-block.tsx Updated to use React Query mutations directly, removed manual deployment state management

Sequence Diagram

sequenceDiagram
    participant Component
    participant ReactQuery
    participant API
    participant Cache

    Note over Component,Cache: Child Workflow Deployment Flow (New)
    
    Component->>ReactQuery: useChildDeploymentStatus(workflowId)
    ReactQuery->>Cache: Check cache (30s staleTime)
    alt Cache Hit
        Cache-->>Component: Return cached data
    else Cache Miss
        ReactQuery->>API: GET /api/workflows/{id}/status
        ReactQuery->>API: GET /api/workflows/{id}/deployments
        API-->>ReactQuery: Status + deployment data
        ReactQuery->>Cache: Store result
        Cache-->>Component: Return fresh data
    end

    Note over Component,Cache: Deployment Mutation Flow
    
    Component->>ReactQuery: deployChildWorkflow.mutate({workflowId})
    ReactQuery->>API: POST /api/workflows/{id}/deploy
    API-->>ReactQuery: Deployment result
    ReactQuery->>Cache: invalidateQueries(deploymentStatus)
    ReactQuery->>Cache: Update workflow registry store
    Cache-->>Component: Trigger re-render with fresh data

    Note over Component,Cache: MCP Tool Mutation Flow
    
    Component->>ReactQuery: addToolMutation.mutateAsync(...)
    ReactQuery->>API: POST /api/mcp/workflow-servers/{id}/tools
    API-->>ReactQuery: Tool created
    ReactQuery->>Cache: invalidateQueries(servers, tools)
    Cache-->>Component: Refetch triggered automatically
Loading

@waleedlatif1 waleedlatif1 merged commit fa63af9 into staging Jan 16, 2026
7 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/react-query branch January 16, 2026 20:01
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.

2 participants