fix(subblock-race-condition): check loading state correctly#1141
fix(subblock-race-condition): check loading state correctly#1141icecrasher321 merged 4 commits intostagingfrom
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR addresses a race condition in workflow switching by fixing the order of operations in the SubBlockStore and activeWorkflowId management. The core issue was that React components would re-render immediately when activeWorkflowId changed, but the SubBlockStore wouldn't be populated with the necessary subblock values until after that change, causing components to temporarily display empty states or incorrect data.
The fix involves three key architectural changes:
-
State Population Order: In
setActiveWorkflow(), the SubBlockStore is now populated with subblock values before setting theactiveWorkflowId. This ensures that when components re-render due to the workflow ID change, they have access to the correct data immediately. -
Hydration Error Prevention: The initial loading state is changed from
Date.now()to0in the workflow store andisLoadingis initialized tofalse. This prevents server-client hydration mismatches by ensuring consistent initial values across both environments. -
Proper Load State Tracking: A
hasInitiallyLoadedflag is introduced with a corresponding helper functionhasWorkflowsInitiallyLoaded()to track when the initial workflow load has completed. This prevents premature navigation decisions during page refresh when workflows are still loading from the database.
The changes integrate well with the existing state management architecture, leveraging the established patterns of using Zustand stores (useSubBlockStore, useWorkflowRegistry) and maintaining the existing data flow while fixing the timing issues. The workflow component now properly waits for initial load completion before making navigation decisions, preventing incorrect redirects during the brief loading period.
Confidence score: 4/5
- This PR addresses a well-defined race condition with a logical solution that maintains data consistency
- Score reflects solid architectural understanding and proper state management practices
- Pay close attention to the workflow registry store changes as they modify critical state synchronization logic
3 files reviewed, 1 comment
…oai#1141) * fix(subblock-race-condition): check loading state correctly" ; * clean up * remove useless comments * fix date fallback
Summary
Type of Change
Testing
Manually switch workflows, workspaces, refresh.
Checklist