healthyregions / SDOHPlace

Landing page and data discovery application for SDOH Place Project.
https://sdohplace.org
GNU General Public License v3.0
1 stars 1 forks source link

Fix the infinitely re-rendering of DiscoverArea and its subcomponents #260

Closed pengyin-shan closed 3 months ago

pengyin-shan commented 3 months ago

This PR addresses the issue of infinite re-rendering in DiscoverArea and its subcomponents, which can be observed by adding a console log in the component. The root cause was the useEffect in index.tsx, which is responsible for providing solrObjectResults to all components in DiscoverArea. Without dependencies, the useEffect was running on every render, causing setSolrObjectResults and other state setters to trigger additional renders, leading to the infinite loop.

I've added solrUrl and schema as dependencies, ensuring that <DiscoverArea> and its subcomponents only re-render when these two variables change. I also cleaned up some unused code in index.tsx after making this change.

How to Test

Run the app and navigate to the search page. You should observe only two render cycles, as indicated by the console message in the ResultPanel component. The two renders are expected in development; in production, it should render only once.

Screenshot 2024-08-16 at 12 32 36 PM

Please let me know if this makes sense to you. Please feel free to add more test messages to confirm the fix.

netlify[bot] commented 3 months ago

Deploy Preview for cheerful-treacle-913a24 ready!

Name Link
Latest commit 5acf942bbf955acebd8047dda379ad1d616abd89
Latest deploy log https://app.netlify.com/sites/cheerful-treacle-913a24/deploys/66bf8d4c42f5d2000852d85d
Deploy Preview https://deploy-preview-260--cheerful-treacle-913a24.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.