fix: memoize examples to prevent repeated re-renders when typing in … - #10554
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe change wraps the computation of filtered examples in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Pre-merge checks and finishing touches❌ Failed checks (3 warnings)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (40.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #10554 +/- ##
==========================================
- Coverage 31.47% 31.40% -0.08%
==========================================
Files 1328 1327 -1
Lines 60091 60027 -64
Branches 8986 8986
==========================================
- Hits 18912 18849 -63
Misses 40272 40272
+ Partials 907 906 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Adam-Aghili
left a comment
There was a problem hiding this comment.
LGTM! thank you @keval718
Screen.Recording.2025-11-10.at.4.55.34.PM.mov
deon-sanchez
left a comment
There was a problem hiding this comment.
Great Work @keval718
Problem
When the Template modal was opened, everything loaded correctly initially. However, typing in the search field caused continuous re-renders, leading to performance issues and unexpected repeated rendering of the template cards.
Root Cause
The examples array was being recreated on every render because it was defined using .filter() directly inside the component body. As a result, the useMemo that initializes the Fuse instance (new Fuse(examples, ...)) was being re-triggered each time since examples received a new array reference. This caused the useEffect that depends on fuse and examples to run repeatedly, updating state on each render and creating an infinite re-render cycle.
Fix Implemented
Result
Summary by CodeRabbit