Skip to content

improvement(stores): remove deployment state from Zustand in favor of React Query#3923

Merged
waleedlatif1 merged 1 commit intostagingfrom
waleedlatif1/find-server-sync-stores
Apr 4, 2026
Merged

improvement(stores): remove deployment state from Zustand in favor of React Query#3923
waleedlatif1 merged 1 commit intostagingfrom
waleedlatif1/find-server-sync-stores

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Removed deployment state (deploymentStatuses, needsRedeployment) from Zustand workflow stores — React Query is now the single source of truth
  • Deployment reads use useDeploymentInfo and getQueryClient().getQueryData() instead of Zustand selectors
  • Moved mutation cache invalidation from onSuccess to onSettled (fires on both success and error)
  • Removed dead code: getAllWorkflowsWithValues, getBlockWithValues, revertToDeployedState, DeploymentStatus type, custom-tool-cache utility

Type of Change

  • Improvement / refactor

Testing

Tested manually, lint and type-check pass clean

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
Copy Markdown

vercel bot commented Apr 4, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 4, 2026 0:35am

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 4, 2026

PR Summary

Medium Risk
Medium risk because it changes how deployment status/needs-redeployment are sourced and updated across UI, hooks, and registry hydration; regressions would show up as incorrect deploy state or stale deployment UI until queries refresh.

Overview
Removes deployment state from Zustand by deleting deploymentStatuses/needsRedeployment fields, related types/actions, and helper APIs (revertToDeployedState, getAllWorkflowsWithValues, etc.), making React Query the source of truth for deployment info.

Updates UI and Copilot flows to read deployment status from React Query (useDeploymentInfo / getQueryClient().getQueryData(deploymentKeys.info)) and to rely on query invalidation after deploy-related tool calls rather than mutating Zustand.

Cleans up API/state payloads by dropping deploymentStatuses from workflow/checkpoint/deployment revert state normalization, and refactors deploy/undeploy/activate mutations to invalidate caches in onSettled.

Removes the custom-tool-cache utility and rewires custom tool lookups (and tests) to read directly from the React Query cache via getQueryClient().

Reviewed by Cursor Bugbot for commit 501b7c1. Configure here.

@waleedlatif1 waleedlatif1 force-pushed the waleedlatif1/find-server-sync-stores branch from d9d3485 to 2eed4da Compare April 4, 2026 00:09
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 4, 2026

Greptile Summary

This PR cleanly removes deploymentStatuses and needsRedeployment from Zustand stores (both WorkflowRegistry and WorkflowState) and makes React Query the single source of truth for deployment status. The approach is architecturally sound: deployment info is seeded into the React Query cache during workflow load (loadWorkflowState in the registry store), and all reads are delegated to useDeploymentInfo / getQueryClient().getQueryData(). Dead code (getBlockWithValues, getAllWorkflowsWithValues, revertToDeployedState, the custom-tool-cache utility) is removed and all call sites updated.

Key changes:

  • deploymentStatuses and needsRedeployment removed from WorkflowState and WorkflowRegistryState; React Query cache is seeded on workflow load instead
  • useDeployWorkflow and useUndeployWorkflow mutation callbacks consolidated from onSuccess/onError into a single onSettled (fires on both success and error) — aligning with project conventions
  • getWorkflowWithValues stripped of isDeployed/deployedAt fields; the sole remaining caller (panel.tsx export handler) does not need them
  • All API routes, socket operations, test fixtures, and persistence utilities updated to drop the now-removed fields
  • Two smaller mutations (useUpdateDeploymentVersion, useUpdatePublicApi) were not migrated to onSettled and still use the old onSuccess/onError split — minor inconsistency worth addressing for uniformity

Confidence Score: 5/5

Safe to merge — all remaining findings are P2 style suggestions with no impact on runtime correctness.

The refactor is thorough: all references to the removed Zustand deployment state have been cleaned up across stores, API routes, socket operations, and tests. The React Query seeding pattern in loadWorkflowState is correct, and the onSettled migration for the core deploy/undeploy mutations follows project conventions. The two mutations not yet migrated to onSettled (useUpdateDeploymentVersion, useUpdatePublicApi) are functionally correct — the only concern is stylistic inconsistency within the file.

apps/sim/hooks/queries/deployments.ts — minor inconsistency between the newly migrated mutations and two older ones still using onSuccess/onError.

Important Files Changed

Filename Overview
apps/sim/hooks/queries/deployments.ts Core deployment query/mutation hooks — useDeployWorkflow and useUndeployWorkflow correctly migrated to onSettled; useUpdateDeploymentVersion and useUpdatePublicApi still use the old onSuccess/onError split; stale JSDoc on invalidateDeploymentQueries.
apps/sim/stores/workflows/registry/store.ts Deployment state removed from registry; deployment info now seeded into React Query cache via getQueryClient().setQueryData() during workflow load — clean implementation.
apps/sim/stores/workflows/index.ts Removed getBlockWithValues, getAllWorkflowsWithValues, and the deployment-status lookup from getWorkflowWithValues; isDeployed/deployedAt are no longer exposed from this function — safe since the only remaining caller (panel.tsx export) does not need them.
apps/sim/stores/workflows/registry/types.ts Removed deploymentStatuses, getWorkflowDeploymentStatus, and DeploymentStatus type — types are now leaner and deployment reads go directly to React Query.
apps/sim/stores/workflows/workflow/types.ts Removed deploymentStatuses and needsRedeployment from WorkflowState — clean removal with no remaining references in the codebase.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/deploy.tsx Now reads isDeployed from useDeploymentInfo React Query hook; correctly gates useDeployedWorkflowState on isDeployed to avoid unnecessary fetches.
apps/sim/app/api/workflows/[id]/route.ts Removed deploymentStatuses: {} placeholder from both the populated and empty workflow state responses — straightforward cleanup.
apps/sim/lib/workflows/defaults.ts Removed deploymentStatuses: {} and needsRedeployment: false from the default workflow state builder — clean removal.
apps/sim/socket/database/operations.ts Removed deploymentStatuses: {} from the socket database workflow state response — consistent with the overall removal.
apps/sim/hooks/queries/utils/custom-tool-cache.ts Deleted as dead code — no remaining consumers after the deployment state refactor.

Sequence Diagram

sequenceDiagram
    participant C as Component
    participant RQ as React Query Cache
    participant ZS as Zustand Store
    participant API as API Route

    Note over C,API: Before this PR — dual source of truth
    C->>ZS: read deploymentStatuses / needsRedeployment
    C->>RQ: read useDeploymentInfo
    API-->>ZS: write on deploy/undeploy
    API-->>RQ: invalidate on deploy/undeploy

    Note over C,API: After this PR — React Query is single source of truth
    C->>RQ: useDeploymentInfo(workflowId)
    RQ-->>C: isDeployed, deployedAt, needsRedeployment

    C->>API: POST /api/workflows/id/deploy
    API-->>RQ: onSettled → invalidateDeploymentQueries()
    RQ-->>C: fresh deployment info

    ZS->>RQ: loadWorkflowState() seeds cache via setQueryData()
Loading

Reviews (3): Last reviewed commit: "improvement(stores): remove deployment s..." | Re-trigger Greptile

@waleedlatif1 waleedlatif1 force-pushed the waleedlatif1/find-server-sync-stores branch from 2eed4da to 6025ef9 Compare April 4, 2026 00:17
@waleedlatif1 waleedlatif1 force-pushed the waleedlatif1/find-server-sync-stores branch from 6025ef9 to af3e12d Compare April 4, 2026 00:19
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

@waleedlatif1 waleedlatif1 force-pushed the waleedlatif1/find-server-sync-stores branch from 2ea7b05 to 0263897 Compare April 4, 2026 00:33
@waleedlatif1 waleedlatif1 force-pushed the waleedlatif1/find-server-sync-stores branch from 0263897 to 501b7c1 Compare April 4, 2026 00:35
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 501b7c1. Configure here.

@waleedlatif1 waleedlatif1 merged commit 65fc138 into staging Apr 4, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/find-server-sync-stores branch April 4, 2026 00:44
waleedlatif1 added a commit that referenced this pull request Apr 4, 2026
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