Skip to content

fix: memory leak and layout shift in finance page (#5114)#5118

Open
Sahitya0805 wants to merge 2 commits intoasyncapi:masterfrom
Sahitya0805:fix-5114-finance
Open

fix: memory leak and layout shift in finance page (#5114)#5118
Sahitya0805 wants to merge 2 commits intoasyncapi:masterfrom
Sahitya0805:fix-5114-finance

Conversation

@Sahitya0805
Copy link

@Sahitya0805 Sahitya0805 commented Feb 9, 2026

Fixes #5114. Removed unstable resize listener in finance page and moved layout logic to CSS to prevent memory leaks and CLS. Also addressed a hydration mismatch in BarChartComponent.

Summary by CodeRabbit

  • Refactor

    • Chart now renders with fixed dimensions (800x400) only after mount; a loading placeholder displays until ready.
    • Page layout simplified to a consistent fluid container, removing dynamic viewport-based responsive branching.
    • Responsive width state and resize-driven logic removed for simpler layout handling.
  • UI

    • Explicit chart container height and an Expenses section shown on larger screens; placeholders used while initializing.

@netlify
Copy link

netlify bot commented Feb 9, 2026

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 866e466
🔍 Latest deploy log https://app.netlify.com/projects/asyncapi-website/deploys/6989cd4e3b6c960008b19475
😎 Deploy Preview https://deploy-preview-5118--asyncapi-website.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 project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 9, 2026

📝 Walkthrough

Walkthrough

Deferred chart rendering behind a mounted flag and removed runtime window resize handling across the Finance page and BarChart component; chart now renders with fixed dimensions and a loading fallback, and page layout no longer depends on client-side window width checks.

Changes

Cohort / File(s) Summary
Chart Rendering Simplification
components/FinancialSummary/BarChartComponent.tsx
Removed window resize listener and windowWidth state. Introduced isMounted gating; render BarChart only after mount with fixed width=800 and height=400. Added loading placeholder and moved category/month data preparation to run after mount.
Layout Simplification
pages/finance.tsx
Eliminated windowWidth state, resize handler/ref, and conditional container rendering. Always render inside a single fluid Container with responsive classes; removed client-side width checks that caused layout shifts.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰
I waited till mount, no more resize chase,
Charts stay steady in their fixed little place.
No leaking listeners trailing behind,
A tidy page now — peaceful and kind.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: fixing memory leak and layout shift in the finance page through removal of unstable resize listeners and CSS-based layout.
Linked Issues check ✅ Passed The PR successfully addresses both coding requirements from issue #5114: eliminating the memory leak by removing the unstable resize listener and fixing layout shift by moving layout logic to CSS with fixed container dimensions.
Out of Scope Changes check ✅ Passed All changes are directly scoped to addressing the memory leak and layout shift issues; modifications are limited to the finance page and BarChartComponent with no extraneous changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Feb 9, 2026

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 39
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-5118--asyncapi-website.netlify.app/

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@components/FinancialSummary/BarChartComponent.tsx`:
- Around line 92-118: The BarChart is using a hardcoded width (width={800})
which causes horizontal overflow on small viewports; modify BarChartComponent to
import ResponsiveContainer from 'recharts' and wrap the <BarChart ...> inside
<ResponsiveContainer width="100%" height="100%"> (or height={400} on the
container) and remove the fixed width/height props from <BarChart>, preserving
existing props like data={chartData}, <CartesianGrid/>, <YAxis/>, <Tooltip
content={<CustomTooltip/>}/>, <Legend/> and the <Bar dataKey='Amount' ... />
click handler so the chart becomes fluid while still guarded by the isMounted
check.
🧹 Nitpick comments (1)
pages/finance.tsx (1)

22-36: renderComponents is now unnecessary indirection.

Since the conditional rendering based on windowWidth has been removed, this wrapper function serves no purpose — its contents can be inlined directly into the return.

♻️ Inline the JSX
 export default function FinancialSummary() {
   const title = 'AsyncAPI Finance Summary';
   const description = 'Financial Summary of AsyncAPI';
 
-  const renderComponents = () => (
-    <>
-      <Head>
-        <title>{title}</title>
-        <meta name='description' content={description} />
-      </Head>
-      <AsyncAPISummary />
-      <SponsorshipTiers />
-      <OtherFormsComponent />
-      <ExpenseBreakdown />
-      <BarChartComponent />
-      <SuccessStories />
-      <ContactUs />
-    </>
-  );
-
   return (
     <Container
       fluid
       className='min-[1701px]:mx-auto min-[1701px]:w-full min-[1701px]:max-w-screen-xl'
       padding='none'
     >
-      {renderComponents()}
+      <Head>
+        <title>{title}</title>
+        <meta name='description' content={description} />
+      </Head>
+      <AsyncAPISummary />
+      <SponsorshipTiers />
+      <OtherFormsComponent />
+      <ExpenseBreakdown />
+      <BarChartComponent />
+      <SuccessStories />
+      <ContactUs />
     </Container>
   );
 }

Comment on lines +92 to +118
<div className='flex justify-center h-[400px]'>
{isMounted ? (
<BarChart width={800} height={400} data={chartData}>
<CartesianGrid strokeDasharray='3 3' />
<YAxis tickFormatter={(value) => `$${value}`} />
<Tooltip content={<CustomTooltip />} />
<Legend />
<Bar
dataKey='Amount'
fill='#7B5DD3FF'
onClick={(data) => {
const category = data.payload.Category;
const matchedLinkObject: ExpensesLinkItem | undefined = ExpensesLinkData.find(
(obj) => obj.category === category
);

if (matchedLinkObject) {
window.open(matchedLinkObject.link, '_blank');
}
}}
/>
</BarChart>
if (matchedLinkObject) {
window.open(matchedLinkObject.link, '_blank');
}
}}
/>
</BarChart>
) : (
<div className='h-[400px] w-full flex items-center justify-center bg-gray-50 rounded-lg'>
Loading chart...
</div>
)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fixed width={800} will cause horizontal overflow on viewports narrower than 800px.

The hardcoded width means the chart won't adapt to smaller screens, causing a horizontal scrollbar or clipping. This replaces one layout problem (CLS) with another (overflow). Use recharts' ResponsiveContainer to make the chart fluid.

🔧 Proposed fix using ResponsiveContainer

Add ResponsiveContainer to the recharts import:

-import { Bar, BarChart, CartesianGrid, Legend, Tooltip, YAxis } from 'recharts';
+import { Bar, BarChart, CartesianGrid, Legend, ResponsiveContainer, Tooltip, YAxis } from 'recharts';

Then replace the fixed-dimension chart:

-        <div className='flex justify-center h-[400px]'>
+        <div className='h-[400px] w-full'>
           {isMounted ? (
-            <BarChart width={800} height={400} data={chartData}>
-              <CartesianGrid strokeDasharray='3 3' />
-              <YAxis tickFormatter={(value) => `$${value}`} />
-              <Tooltip content={<CustomTooltip />} />
-              <Legend />
-              <Bar
-                dataKey='Amount'
-                fill='#7B5DD3FF'
-                onClick={(data) => {
-                  const category = data.payload.Category;
-                  const matchedLinkObject: ExpensesLinkItem | undefined = ExpensesLinkData.find(
-                    (obj) => obj.category === category
-                  );
-
-                  if (matchedLinkObject) {
-                    window.open(matchedLinkObject.link, '_blank');
-                  }
-                }}
-              />
-            </BarChart>
+            <ResponsiveContainer width='100%' height={400}>
+              <BarChart data={chartData}>
+                <CartesianGrid strokeDasharray='3 3' />
+                <YAxis tickFormatter={(value) => `$${value}`} />
+                <Tooltip content={<CustomTooltip />} />
+                <Legend />
+                <Bar
+                  dataKey='Amount'
+                  fill='#7B5DD3FF'
+                  onClick={(data) => {
+                    const category = data.payload.Category;
+                    const matchedLinkObject: ExpensesLinkItem | undefined = ExpensesLinkData.find(
+                      (obj) => obj.category === category
+                    );
+
+                    if (matchedLinkObject) {
+                      window.open(matchedLinkObject.link, '_blank');
+                    }
+                  }}
+                />
+              </BarChart>
+            </ResponsiveContainer>
           ) : (

ResponsiveContainer handles resize internally via its own ResizeObserver, and since it's rendered only after mount (behind the isMounted guard), it won't cause hydration mismatches.

🤖 Prompt for AI Agents
In `@components/FinancialSummary/BarChartComponent.tsx` around lines 92 - 118, The
BarChart is using a hardcoded width (width={800}) which causes horizontal
overflow on small viewports; modify BarChartComponent to import
ResponsiveContainer from 'recharts' and wrap the <BarChart ...> inside
<ResponsiveContainer width="100%" height="100%"> (or height={400} on the
container) and remove the fixed width/height props from <BarChart>, preserving
existing props like data={chartData}, <CartesianGrid/>, <YAxis/>, <Tooltip
content={<CustomTooltip/>}/>, <Legend/> and the <Bar dataKey='Amount' ... />
click handler so the chart becomes fluid while still guarded by the isMounted
check.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 9, 2026

@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7653853) to head (866e466).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #5118   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines          796       796           
  Branches       146       146           
=========================================
  Hits           796       796           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Sahitya0805
Copy link
Author

Just following up on the PR I raised.
Looking forward to your feedback. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To Be Triaged

Development

Successfully merging this pull request may close these issues.

[BUG]: Memory leak and layout shift in Finance page (pages/finance.tsx)

2 participants

Comments