You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .jules/bolt.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -158,3 +158,6 @@
158
158
## 2026-05-12 - [Recursive Timeout vs Synchronous Functions]
159
159
**Learning:** While replacing `setInterval` with recursive `setTimeout` is a best practice for asynchronous network polling (like in `GlobalNav.tsx` or `usePromptFeed.ts`) to prevent request pile-ups, blindly applying this pattern to purely local, synchronous state updates (like mock data generation in `NewsWire.tsx`) provides zero performance benefit and unnecessarily complicates the code with boilerplate `try/catch` and `isMounted` checks.
160
160
**Action:** Only use the recursive `setTimeout` pattern when dealing with `async`/`await` operations or external I/O. For pure synchronous local state intervals, standard `setInterval` is sufficient, or better yet, refactor the mock generation to a worker if it's genuinely heavy.
**Learning:**`setInterval` inside React component `useEffect` blocks can pile up and cause performance lags if component unmounts happen improperly, or if the process lags. Using recursive `setTimeout` guarded by `isMounted` prevents duplicate runs and handles cleanup reliably. Similarly, using the array index (`key={i}`) inside React map functions directly defeats memoization, especially in arrays that change (like a sliding log window using `.slice`), forcing full O(N) re-renders.
163
+
**Action:** Always replace `setInterval` with recursive `setTimeout` for asynchronous component updates (especially data polling/simulations) and always assign a unique, stable string/ID for `key` props during mapping, even using random string generation for completely un-keyed simulated inputs.
1. Modify `services/webapp/client/src/hooks/useSwarmSimulation.ts` to extract only the `initializeSwarm` method, instead of `agents`, to prevent it from subscribing its parent (`PromptAlpha.tsx`) to every single state change from the simulation loop. It will use `.getState()` to access the latest state.
2
-
2. Replace `setInterval` in `services/webapp/client/src/hooks/useSwarmSimulation.ts` with a recursive `setTimeout` to follow the journal guidelines.
3
-
3. Test by running lint.
1
+
1.**Analyze target changes**: Replace `setInterval` with recursive `setTimeout` guarded by an `isMounted` flag and `try/catch` (where applicable) across the React app and HTML showcases, following memory rules.
2
+
2.**Implement changes in components**:
3
+
-`services/webapp/client/src/components/promptAlpha/NewsWire.tsx`: Replace `setInterval` with recursive `setTimeout`.
4
+
-`services/webapp/client/src/components/dashboard/NeuralDashboard.js`: Replace `setInterval` with recursive `setTimeout`.
5
+
3.**Implement changes in utilities and hooks**:
6
+
-`services/webapp/client/src/hooks/usePromptFeed.ts`: Replace `setInterval` with recursive `setTimeout`.
7
+
-`services/webapp/client/src/utils/DataManager.ts`: Replace `setInterval` with recursive `setTimeout`.
8
+
4.**Fix React `key={i}` Anti-Pattern**: Fix array index usage in `key` attribute to use a stable, unique identifier:
9
+
-`services/webapp/client/src/components/promptAlpha/SystemMonitor.tsx`: Array index used in mapping `Memory Allocation`. Generate a stable key or use a pre-computed array of IDs.
10
+
-`services/webapp/client/src/components/ConvictionMeter.tsx`: Array index used in reasoning map. Use string hash or counter map.
11
+
-`services/webapp/client/src/components/Terminal.tsx`: Array index used in `history.map` (`<div key={i} ...>`). The memory rule explicitly mentions this one ("do not use the array index (`key={i}`) as the React key, as this fundamentally defeats memoization...").
12
+
-`services/webapp/client/src/pages/EvolutionHub.tsx`: Array index used in multiple maps (constraints, metrics, agents). Replace with stable identifiers.
13
+
-`showcase/credit_valuation_architect.html` and `showcase/credit_architect.html`: Array index used in mapping arrays.
14
+
5.**Pre-commit**: Complete pre-commit steps to ensure proper testing, verification, review, and reflection are done.
15
+
6.**Submit**: Run tests/verification and submit the code.
0 commit comments