1.2 KiB
1.2 KiB
Bug Fix: React Render Error and Pack Generation Stability
Issue
User reported "root.render(" error visible on page and "Generate Packs" button ineffective.
Diagnosis
- main.tsx: Found nested
root.render( <StrictMode> root.render(...) )call. This caused runtime errors and visible artifact text. - CubeManager.tsx: Service classes (
ScryfallService,PackGeneratorService) were instantiated inside the functional component body withoutuseMemo. This caused recreation on every render, leading to cache loss (ScryfallServiceinternal cache) and potential state inconsistencies. - Pack Generation: Double-clicking or rapid state updates caused "phantom" generation runs with empty pools, resetting the packs list to 0 immediately after success.
Resolution
- Fixed main.tsx: Removed the nested
root.rendercall. - Refactored CubeManager.tsx:
- Memoized all services using
useMemo. - Added
loadingstate togeneratePacksto prevent double-submissions. - Wrapped generation logic in
setTimeoutto allow UI updates andtry/catchfor robustness.
- Memoized all services using
Status
Verified via browser subagent (logs confirmed 241 packs generated). UI now prevents race conditions.