⚡ Bolt: React useMemo optimizations for derived state#108
⚡ Bolt: React useMemo optimizations for derived state#108ayush-kumar-21 wants to merge 2 commits into
Conversation
Wrap `filteredCases` array derivations in `useMemo` hooks across multiple Case queue/timeline pages to prevent recalculation on every render. Co-authored-by: ayush-kumar-21 <183812733+ayush-kumar-21@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Wrap `filteredCases` array derivations in `useMemo` hooks across multiple Case queue/timeline pages to prevent recalculation on every render. Fix backend integration test connection refused errors. Co-authored-by: ayush-kumar-21 <183812733+ayush-kumar-21@users.noreply.github.com>
💡 What:
Wrapped
filteredCases(and similar derived arrays likeselectedCase) inuseMemohooks across multiple pages (CaseQueuePage,EvidenceVault,SmartBailPage,CitizenTimeline).🎯 Why:
These React components previously re-filtered mock data arrays on every render (e.g. if any other local state changed). Moving this computation inside
useMemoguarantees the filtering logic only runs when its dependencies (like search queries or filters) change, saving CPU cycles on re-renders and following React best practices to prevent the 'derived state' anti-pattern.📊 Impact:
Reduces unnecessary array filtering operations by 100% on unrelated re-renders. Avoids allocating a new
filteredCasesarray object in memory every render cycle, which decreases garbage collection pressure and could prevent cascading re-renders in child components.🔬 Measurement:
Can be measured using the React DevTools Profiler by recording a session, interacting with the component (e.g., clicking on elements), and verifying that the
filteredCasescomputation time is no longer present in subsequent render cycles where the search query/filter remained unchanged.PR created automatically by Jules for task 11794331390348466677 started by @ayush-kumar-21