fix(hydration): duplicate overlay after idle + subblocks race condition#1246
fix(hydration): duplicate overlay after idle + subblocks race condition#1246icecrasher321 merged 6 commits intostagingfrom
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR fixes two critical hydration issues in the workflow management system: duplicate overlay problems after idle time and subblock loading race conditions.
The main changes involve replacing merge-based state synchronization with direct replacement logic in the socket context handlers. Previously, the 'copilot-workflow-edit' and 'workflow-state' socket events merged incoming server state with existing local state to preserve optimistic updates. Now, these handlers completely replace the local state with authoritative server state using useWorkflowStore.setState() and useSubBlockStore.setState(). This eliminates merge conflicts that were causing duplicate overlays to appear after periods of inactivity.
Additionally, the PR adds initialization safety checks in the workflow component to ensure subblock values are properly initialized before marking workflows as ready. When blocks exist but corresponding subblock values are missing, the code now initializes them synchronously from the block structure. This prevents race conditions where the workflow UI would render before subblock values were fully loaded.
The changes integrate with the existing state management architecture where workflows maintain separate stores for block definitions (useWorkflowStore) and dynamic values (useSubBlockStore). The fix ensures these stores remain synchronized and that server state always takes precedence over potentially stale local state.
Confidence score: 3/5
- This PR addresses real issues but introduces trade-offs that could impact user experience and system reliability
- Score reflects concerns about losing optimistic updates, potential performance implications, and the complexity of direct state mutations in effects
- Pay close attention to the socket context changes and workflow initialization logic for potential edge cases
2 files reviewed, 3 comments
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx
Outdated
Show resolved
Hide resolved
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx
Outdated
Show resolved
Hide resolved
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx
Outdated
Show resolved
Hide resolved
…on (simstudioai#1246) * fix(hydration): duplicate overlay after idle + subblocks race condition * remove random timeout * re-use correct helper * remove redundant check * add check * remove third init func
Summary
Type of Change
Testing
Manually
Checklist