Skip to content

fix(subblock-race-condition): check loading state correctly#1141

Merged
icecrasher321 merged 4 commits intostagingfrom
fix/subblock-race-cond
Aug 26, 2025
Merged

fix(subblock-race-condition): check loading state correctly#1141
icecrasher321 merged 4 commits intostagingfrom
fix/subblock-race-cond

Conversation

@icecrasher321
Copy link
Collaborator

Summary

  • Populate SubBlockStore with subblock values BEFORE changing activeWorkflowId in setActiveWorkflow(), ensuring data is available when components re-render after the workflow switch.
  • Fix hydration error

Type of Change

  • Bug fix

Testing

Manually switch workflows, workspaces, refresh.

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 Aug 26, 2025

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

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Aug 26, 2025 6:42pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Aug 26, 2025 6:42pm

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

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:

  1. State Population Order: In setActiveWorkflow(), the SubBlockStore is now populated with subblock values before setting the activeWorkflowId. This ensures that when components re-render due to the workflow ID change, they have access to the correct data immediately.

  2. Hydration Error Prevention: The initial loading state is changed from Date.now() to 0 in the workflow store and isLoading is initialized to false. This prevents server-client hydration mismatches by ensuring consistent initial values across both environments.

  3. Proper Load State Tracking: A hasInitiallyLoaded flag is introduced with a corresponding helper function hasWorkflowsInitiallyLoaded() 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

Edit Code Review Bot Settings | Greptile

@vercel vercel bot temporarily deployed to Preview – docs August 26, 2025 18:32 Inactive
@vercel vercel bot temporarily deployed to Preview – docs August 26, 2025 18:34 Inactive
@icecrasher321 icecrasher321 merged commit 3b74250 into staging Aug 26, 2025
5 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/subblock-race-cond branch August 27, 2025 06:12
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
…oai#1141)

* fix(subblock-race-condition): check loading state correctly"
;

* clean up

* remove useless comments

* fix date fallback
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