Skip to content

fix: memory leak and layout shift issue#5119

Open
krishhna24 wants to merge 1 commit intoasyncapi:masterfrom
krishhna24:fix/finance-resize-listener
Open

fix: memory leak and layout shift issue#5119
krishhna24 wants to merge 1 commit intoasyncapi:masterfrom
krishhna24:fix/finance-resize-listener

Conversation

@krishhna24
Copy link
Copy Markdown

@krishhna24 krishhna24 commented Feb 9, 2026

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Enhanced the finance page's layout stability through improved window resize event handling, ensuring consistent and reliable rendering when users resize their browser window or visit at different viewport widths.

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 9, 2026

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 5070c37
🔍 Latest deploy log https://app.netlify.com/projects/asyncapi-website/deploys/6989d474a12198000789eb63
😎 Deploy Preview https://deploy-preview-5119--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.

Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 9, 2026

📝 Walkthrough

Walkthrough

Refactors the window resize handling in pages/finance.tsx from a useRef-based pattern to a useEffect-based approach with null-initialized state. Delays rendering until windowWidth is known to prevent hydration mismatches and layout shifts. Updates layout wrapping logic based on the resolved width and adds proper event listener cleanup.

Changes

Cohort / File(s) Summary
Window Resize Refactoring
pages/finance.tsx
Replaces useRef-based resize handling with useEffect and state-based windowWidth tracking. Initializes windowWidth as null to prevent hydration/CLS, sets initial width on mount, updates on resize events, and delays rendering until width is known. Changes layout logic to use container divs conditionally based on windowWidth. Includes proper cleanup for the resize event listener. Minor JSX attribute normalization applied.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 When windows do resize and dance all about,
A rabbit refactors, the shifts iron out,
useEffect takes over what useRef once knew,
No hydration mismatch—the layout stays true! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title accurately describes the main changes: fixing a memory leak in the resize event listener and eliminating layout shift through better hydration handling.

✏️ 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

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.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Feb 9, 2026

@asyncapi-bot
Copy link
Copy Markdown
Contributor

⚡️ Lighthouse report for the changes in this PR:

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

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

Copy link
Copy Markdown
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: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
pages/finance.tsx (2)

11-11: ⚠️ Potential issue | 🟡 Minor

Remove unused Container import — pipeline is failing on this.

The Container import is no longer used since the layout now uses plain <div> elements with Tailwind classes. The linter flags this as an error.

Proposed fix
-import Container from '../components/layout/Container';

18-73: 🛠️ Refactor suggestion | 🟠 Major

If the layout is now CSS-driven, the entire windowWidth machinery is dead code.

The PR description says: "Removes JavaScript-driven layout switching and replaces it with CSS breakpoints." The JSX on lines 68-72 already uses Tailwind 2xl: utility classes to handle the layout breakpoint purely in CSS. That means:

  • windowWidth state (line 20)
  • handleResize (lines 21-24)
  • The useEffect (lines 27-38)
  • The null-guard (lines 60-63)
  • shouldUseContainer (line 65)

…are all unnecessary. Removing them fully delivers on the PR objective, eliminates the SSR/SEO blank-page issue, and removes the resize listener entirely (which was the original memory-leak concern).

Simplified component
 export default function FinancialSummary() {
-  const [windowWidth, setWindowWidth] = useState<number | null>(null);
-   const handleResize = () => {
-    console.log("resized")
-      setWindowWidth(window.innerWidth);
-    };
-
-  useEffect(() => {
-
-
-    handleResize();
-
-    window.addEventListener('resize', handleResize);
-
-    return () => {
-      window.removeEventListener('resize', handleResize);
-    };
-  }, []);
-
   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 />
-    </>
-  );
-
-  if (windowWidth === null) {
-    return null;
-  }
-
-  const shouldUseContainer = windowWidth > 1700;
-
   return (
-    <div className="w-full">
-  <div className="2xl:container 2xl:mx-auto 2xl:px-8">
-    {renderComponents()}
-  </div>
-</div>
+    <div className='w-full'>
+      <Head>
+        <title>{title}</title>
+        <meta name='description' content={description} />
+      </Head>
+      <div className='2xl:container 2xl:mx-auto 2xl:px-8'>
+        <AsyncAPISummary />
+        <SponsorshipTiers />
+        <OtherFormsComponent />
+        <ExpenseBreakdown />
+        <BarChartComponent />
+        <SuccessStories />
+        <ContactUs />
+      </div>
+    </div>
   );
 }

This also lets you drop the useEffect and useState imports, and the unused Container import.

🤖 Fix all issues with AI agents
In `@pages/finance.tsx`:
- Around line 67-73: The JSX return block in pages/finance.tsx has inconsistent
indentation and uses double quotes in JSX attributes violating jsx-quotes; fix
the indentation so the inner <div> and its child {renderComponents()} are
indented one level inside the outer <div>, and change JSX attribute quotes from
double to single quotes (e.g., className attributes) to satisfy the linter;
locate the return block containing renderComponents() and adjust spacing and
quote style accordingly.
- Line 65: Remove the unused JS-driven layout sizing: delete the
shouldUseContainer constant and the windowWidth state plus its useEffect (and
any window resize handler or cleanup) in pages/finance.tsx, ensuring you also
remove unused imports (useState/useEffect) if they become unused; verify no
other code references windowWidth or shouldUseContainer and rely on the CSS
breakpoints (e.g., 2xl:) instead.
- Around line 60-63: The current guard returning null when windowWidth === null
causes blank SSR output; remove the early return and always render the component
(e.g., keep the exported Finance component JSX) and rely on CSS-driven
breakpoints (the existing 2xl: classes) or a sensible default layout until the
client effect sets windowWidth; update any conditional branches that depended on
windowWidth to fall back to a default (wide or narrow) when windowWidth is null,
and remove the null-check return to prevent empty HTML being sent to crawlers.
- Around line 19-24: The component currently defines handleResize in the render
body and includes a debug console.log and double quotes plus bad indentation;
move the handleResize function inside the useEffect that subscribes to resizing,
remove the console.log, use single quotes for any strings (e.g., 'resized' if
needed, though remove entirely here), and fix indentation around the useState
declaration and effect; update references to windowWidth and setWindowWidth
accordingly and ensure the effect adds/removes the resize listener and lists no
unnecessary dependencies (no eslint-disable needed because the handler is
declared inside useEffect).

Comment on lines +19 to +24
// Initialize as null to avoid hydration/layout shift
const [windowWidth, setWindowWidth] = useState<number | null>(null);
const handleResize = () => {
console.log("resized")
setWindowWidth(window.innerWidth);
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Remove console.log, fix formatting, and move handleResize inside useEffect.

Multiple pipeline-failing issues here:

  1. console.log("resized") is a debug artifact — the linter rejects it (no-console).
  2. Double quotes must be single quotes (quotes rule).
  3. Indentation is inconsistent (extra leading space on line 21, extra indent on lines 23-24).
  4. Defining handleResize in the component body means a new reference is created each render, yet it's omitted from the useEffect deps. Move it inside the effect to keep the closure tight and avoid the stale-reference concern.
Proposed fix (move handler into useEffect)
-  // Initialize as null to avoid hydration/layout shift
-  const [windowWidth, setWindowWidth] = useState<number | null>(null);
-   const handleResize = () => {
-    console.log("resized")
-      setWindowWidth(window.innerWidth);
-    };
-
-  // Properly scoped resize handler with correct cleanup
-  useEffect(() => {
-
-
-    // Set initial width on mount
-    handleResize();
-
-    window.addEventListener('resize', handleResize);
-
-    return () => {
-      window.removeEventListener('resize', handleResize);
-    };
-  }, []);
+  const [windowWidth, setWindowWidth] = useState<number | null>(null);
+
+  useEffect(() => {
+    const handleResize = () => {
+      setWindowWidth(window.innerWidth);
+    };
+
+    handleResize();
+    window.addEventListener('resize', handleResize);
+
+    return () => {
+      window.removeEventListener('resize', handleResize);
+    };
+  }, []);

Based on learnings: when intentionally omitting dependencies in React hooks, add an eslint-disable comment with an explanatory note. Here, moving the handler inside the effect eliminates the need for that.

🧰 Tools
🪛 GitHub Actions: PR testing - if Node project

[error] 21-21: Delete · prettier/prettier


[error] 22-22: Unexpected console statement. no-console


[error] 22-22: Replace "resized" ) with 'resized'); prettier/prettier


[error] 22-22: Strings must use singlequote. quotes


[error] 23-23: Delete ·· prettier/prettier


[error] 24-24: Delete ·· prettier/prettier

🤖 Prompt for AI Agents
In `@pages/finance.tsx` around lines 19 - 24, The component currently defines
handleResize in the render body and includes a debug console.log and double
quotes plus bad indentation; move the handleResize function inside the useEffect
that subscribes to resizing, remove the console.log, use single quotes for any
strings (e.g., 'resized' if needed, though remove entirely here), and fix
indentation around the useState declaration and effect; update references to
windowWidth and setWindowWidth accordingly and ensure the effect adds/removes
the resize listener and lists no unnecessary dependencies (no eslint-disable
needed because the handler is declared inside useEffect).

Comment on lines +60 to +63
// Avoid rendering until window size is known (prevents CLS)
if (windowWidth === null) {
return null; // or a skeleton/loading placeholder
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Returning null until client-side width is resolved hurts SSR/SEO and causes a flash of empty content.

Because windowWidth is null on the server (and on the first client render before the effect fires), this page will:

  • Send an empty HTML response to search engines / social-media crawlers.
  • Flash a blank screen before hydration completes.

This trades the original layout-shift problem for a blank-page problem. A better approach is to always render the content using a sensible default layout (e.g., the wide or narrow variant) and only switch once the width is known, or use CSS-only breakpoints for the layout difference (which the new JSX on lines 68-72 already does via 2xl: classes). If the layout is purely CSS-driven, you don't need the windowWidth guard at all.

Proposed fix — remove the null guard
-  // Avoid rendering until window size is known (prevents CLS)
-  if (windowWidth === null) {
-    return null; // or a skeleton/loading placeholder
-  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Avoid rendering until window size is known (prevents CLS)
if (windowWidth === null) {
return null; // or a skeleton/loading placeholder
}
🤖 Prompt for AI Agents
In `@pages/finance.tsx` around lines 60 - 63, The current guard returning null
when windowWidth === null causes blank SSR output; remove the early return and
always render the component (e.g., keep the exported Finance component JSX) and
rely on CSS-driven breakpoints (the existing 2xl: classes) or a sensible default
layout until the client effect sets windowWidth; update any conditional branches
that depended on windowWidth to fall back to a default (wide or narrow) when
windowWidth is null, and remove the null-check return to prevent empty HTML
being sent to crawlers.

return null; // or a skeleton/loading placeholder
}

const shouldUseContainer = windowWidth > 1700;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Remove unused shouldUseContainer — pipeline is failing on this.

This variable is computed but never referenced. If the layout is now CSS-driven (2xl: breakpoints), the JS-based width check is dead code. Remove it along with the windowWidth state and effect if they serve no other purpose.

Proposed fix
-  const shouldUseContainer = windowWidth > 1700;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const shouldUseContainer = windowWidth > 1700;
🧰 Tools
🪛 GitHub Actions: PR testing - if Node project

[error] 65-65: ShouldUseContainer is assigned a value but never used. no-unused-vars


[error] 65-65: ShouldUseContainer is assigned a value but never used. @typescript-eslint/no-unused-vars


[error] 65-65: ShouldUseContainer is assigned a value but never used. unused-imports/no-unused-vars

🤖 Prompt for AI Agents
In `@pages/finance.tsx` at line 65, Remove the unused JS-driven layout sizing:
delete the shouldUseContainer constant and the windowWidth state plus its
useEffect (and any window resize handler or cleanup) in pages/finance.tsx,
ensuring you also remove unused imports (useState/useEffect) if they become
unused; verify no other code references windowWidth or shouldUseContainer and
rely on the CSS breakpoints (e.g., 2xl:) instead.

Comment on lines +67 to +73
return (
<div className="w-full">
<div className="2xl:container 2xl:mx-auto 2xl:px-8">
{renderComponents()}
</div>
</div>
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix indentation and quote style — multiple prettier/lint failures.

The JSX block uses double quotes (violating jsx-quotes) and inconsistent indentation (the inner <div> and children are not properly indented relative to the outer <div>).

Proposed fix
-  return (
-    <div className="w-full">
-  <div className="2xl:container 2xl:mx-auto 2xl:px-8">
-    {renderComponents()}
-  </div>
-</div>
-  );
+  return (
+    <div className='w-full'>
+      <div className='2xl:container 2xl:mx-auto 2xl:px-8'>
+        {renderComponents()}
+      </div>
+    </div>
+  );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return (
<div className="w-full">
<div className="2xl:container 2xl:mx-auto 2xl:px-8">
{renderComponents()}
</div>
</div>
);
return (
<div className='w-full'>
<div className='2xl:container 2xl:mx-auto 2xl:px-8'>
{renderComponents()}
</div>
</div>
);
🧰 Tools
🪛 GitHub Actions: PR testing - if Node project

[error] 68-68: Replace "w-full" with 'w-full' prettier/prettier


[error] 68-68: Unexpected usage of doublequote. jsx-quotes


[error] 69-69: Replace <div className="2xl:container 2xl:mx-auto 2xl:px-8">\n····{renderComponents()}\n·· with <div className='2xl:container 2xl:mx-auto 2xl:px-8'>{renderComponents()} prettier/prettier


[error] 69-69: Unexpected usage of doublequote. jsx-quotes


[error] 72-72: Insert prettier/prettier

🤖 Prompt for AI Agents
In `@pages/finance.tsx` around lines 67 - 73, The JSX return block in
pages/finance.tsx has inconsistent indentation and uses double quotes in JSX
attributes violating jsx-quotes; fix the indentation so the inner <div> and its
child {renderComponents()} are indented one level inside the outer <div>, and
change JSX attribute quotes from double to single quotes (e.g., className
attributes) to satisfy the linter; locate the return block containing
renderComponents() and adjust spacing and quote style accordingly.

@SHUBHANSHU602
Copy link
Copy Markdown
Contributor

fix the title please ,I believe its layout also add the issue number

1 similar comment
@SHUBHANSHU602
Copy link
Copy Markdown
Contributor

fix the title please ,I believe its layout also add the issue number

@yashdarekar17
Copy link
Copy Markdown
Contributor

yashdarekar17 commented Feb 9, 2026

@krishhna24 thanks for your efforts. I think this PR is linked to #5114, but the current author of that issue is already working on it and is waiting for maintainer approval. If you want to work on that issue, you need to ask the author first.

@krishhna24 krishhna24 changed the title fix: memory leak and layou shift issue fix: memory leak and layout shift issue Feb 10, 2026
@krishhna24
Copy link
Copy Markdown
Author

@krishhna24 thanks for your efforts. I think this PR is linked to #5114, but the current author of that issue is already working on it and is waiting for maintainer approval. If you want to work on that issue, you need to ask the author first.

ok @yashdarekar17

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.

4 participants