Skip to content

Conversation

@CodeWithBehnam
Copy link
Owner

Summary

  • Prevent concurrent execution calls using ref-based state tracking
  • Add 300ms cooldown after execution completion to prevent double-clicks
  • Apply debouncing to all execution methods: execute(), executeFromNode(), executeNodeOnly()
  • Update cancel() to properly reset execution state

Technical Details

The implementation uses a dual-protection approach:

  1. isExecutingRef: A synchronous ref (not state) to check if execution is in progress. Using a ref avoids stale closure issues that can occur with useState in rapid async calls.

  2. lastExecutionTimeRef: Tracks when execution last completed, enforcing a 300ms cooldown before allowing another execution.

Why refs instead of state?

React's useState updates are asynchronous and can lead to stale closures when multiple rapid calls occur. By using useRef, we get synchronous, reliable state checking that prevents race conditions.

Test plan

  • bun run typecheck passes
  • bun run lint passes
  • Rapid clicking on execute button only triggers one execution
  • Execution can still be triggered normally after cooldown

Behnam Ebrahimi

- Prevent multiple executions from running concurrently using ref-based
  state tracking (refs are synchronous, avoiding stale closure issues)
- Add 300ms cooldown after execution completion to prevent rapid
  double-clicks from triggering duplicate runs
- Apply debouncing to execute(), executeFromNode(), and executeNodeOnly()
- Update cancel() to properly reset execution state

The dual-protection approach ensures both concurrent execution prevention
and post-execution cooldown for a robust user experience.

Co-Authored-By: Behnam & Claude Code
@CodeWithBehnam CodeWithBehnam merged commit dbee108 into main Dec 25, 2025
2 checks passed
@CodeWithBehnam CodeWithBehnam deleted the perf/execution-debouncing branch December 25, 2025 16:15
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.

2 participants