Refactor: How to fix critical code issues in unified-builder component...

Documentation for Sessions

♻️ Refactor: How to fix critical code issues in unified-builder component...

📋 Decision Context

Question:

How to fix critical code issues in unified-builder components?

Task: Not specified


🎯 Decision Made

Chosen:

Comprehensive refactor fixing 7 critical/significant issues: (1) Moved RxJS subscription out of effect to prevent memory leak, (2) Added document event listener cleanup in ngOnDestroy, (3) Fixed refreshModules() to properly await using firstValueFrom, (4) Replaced sessionStorage with builderState service for tool state persistence, (5) Replaced polling loops with reactive patterns using toObservable + filter + timeout, (6) Removed history push from selection changes to prevent history flooding, (7) Added toolLoadError signal for better UX

Options Considered:

  1. Quick fix each issue individually
  2. Comprehensive refactor of all issues at once
  3. Create new components to replace problematic ones

💭 Reasoning

Effects should never contain RxJS subscriptions as they create new subscriptions on every signal change. Document event listeners must be cleaned up to prevent leaks. Async functions using Observables should use firstValueFrom for proper awaiting. State should be consistent (all flash-persisted vs mixed). Reactive patterns (toObservable) are more reliable than polling loops. Selection changes are too granular for undo/redo history.


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation