fix(rehydration): consolidate store rehydration code#1249
fix(rehydration): consolidate store rehydration code#1249icecrasher321 merged 2 commits intostagingfrom
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR consolidates duplicated store rehydration logic in the socket context by extracting common functionality into a shared rehydrateWorkflowStores function. Previously, two socket event handlers ('copilot-workflow-edit' and 'workflow-state') contained nearly 70 lines of identical code for rehydrating workflow and subblock stores. The refactoring eliminates this duplication by creating a centralized function that handles the rehydration process with proper validation checks.
The consolidation also strengthens the application architecture by making the workflow registry the authoritative source for determining the active workflow. Instead of relying on URL parameters to check if a workflow is active, the code now uses useWorkflowRegistry.getState().activeWorkflowId as the single source of truth. This change reduces potential race conditions and ensures consistent workflow state management across the application.
The new rehydrateWorkflowStores function includes two key validation checks: active workflow verification to ensure rehydration only occurs for the currently active workflow, and pending operations checking to prevent data races during concurrent operations. This fits well with the existing state management pattern in the codebase, which already uses Zustand stores for workflow registry management as seen in the /stores/workflows/registry directory structure.
Confidence score: 4/5
- This PR is safe to merge with minimal risk as it consolidates existing logic without changing core functionality
- Score reflects solid refactoring practices that eliminate code duplication while improving architectural consistency through centralized workflow state management
- Pay close attention to the socket event handler integration points to ensure all rehydration scenarios are properly covered
1 file reviewed, no comments
* fix(rehydration): consolidate store rehydration code * fix stale closure
Summary
Consolidate store rehydration and make registry source of truth for active workflow.
Type of Change
Testing
Manually
Checklist