-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: memory leak and layout shift issue #5119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||||||||||||||||||||||
| import Head from 'next/head'; | ||||||||||||||||||||||||||||||
| import React, { useEffect, useRef, useState } from 'react'; | ||||||||||||||||||||||||||||||
| import React, { useEffect, useState } from 'react'; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import AsyncAPISummary from '../components/FinancialSummary/AsyncAPISummary'; | ||||||||||||||||||||||||||||||
| import BarChartComponent from '../components/FinancialSummary/BarChartComponent'; | ||||||||||||||||||||||||||||||
|
|
@@ -16,21 +16,24 @@ import Container from '../components/layout/Container'; | |||||||||||||||||||||||||||||
| * bar chart, success stories, and contact us components. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| export default function FinancialSummary() { | ||||||||||||||||||||||||||||||
| const [windowWidth, setWindowWidth] = useState<number>(0); | ||||||||||||||||||||||||||||||
| // 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(() => { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const handleResizeRef = useRef<() => void>(null!); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| handleResizeRef.current = () => { | ||||||||||||||||||||||||||||||
| setWindowWidth(window.innerWidth); | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
| // Set initial width on mount | ||||||||||||||||||||||||||||||
| handleResize(); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Handle window resize event to update the window width state value for responsive design purposes | ||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||
| handleResizeRef.current!(); | ||||||||||||||||||||||||||||||
| window.addEventListener('resize', handleResizeRef.current!); | ||||||||||||||||||||||||||||||
| window.addEventListener('resize', handleResize); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| return () => { | ||||||||||||||||||||||||||||||
| window.removeEventListener('resize', handleResizeRef.current!); | ||||||||||||||||||||||||||||||
| window.removeEventListener('resize', handleResize); | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
| }, []); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
@@ -41,8 +44,9 @@ export default function FinancialSummary() { | |||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||
| <Head> | ||||||||||||||||||||||||||||||
| <title>{title}</title> | ||||||||||||||||||||||||||||||
| <meta name='description' content={description} /> | ||||||||||||||||||||||||||||||
| <meta name="description" content={description} /> | ||||||||||||||||||||||||||||||
| </Head> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| <AsyncAPISummary /> | ||||||||||||||||||||||||||||||
| <SponsorshipTiers /> | ||||||||||||||||||||||||||||||
| <OtherFormsComponent /> | ||||||||||||||||||||||||||||||
|
|
@@ -53,7 +57,18 @@ export default function FinancialSummary() { | |||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Avoid rendering until window size is known (prevents CLS) | ||||||||||||||||||||||||||||||
| if (windowWidth === null) { | ||||||||||||||||||||||||||||||
| return null; // or a skeleton/loading placeholder | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+60
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning Because
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 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const shouldUseContainer = windowWidth > 1700; | ||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused This variable is computed but never referenced. If the layout is now CSS-driven ( Proposed fix- const shouldUseContainer = windowWidth > 1700;📝 Committable suggestion
Suggested change
🧰 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. [error] 65-65: ShouldUseContainer is assigned a value but never used. unused-imports/no-unused-vars 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| return <div>{shouldUseContainer ? <Container wide>{renderComponents()}</Container> : renderComponents()}</div>; | ||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||
| <div className="w-full"> | ||||||||||||||||||||||||||||||
| <div className="2xl:container 2xl:mx-auto 2xl:px-8"> | ||||||||||||||||||||||||||||||
| {renderComponents()} | ||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
|
Comment on lines
+67
to
+73
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix indentation and quote style — multiple prettier/lint failures. The JSX block uses double quotes (violating 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
Suggested change
🧰 Tools🪛 GitHub Actions: PR testing - if Node project[error] 68-68: Replace [error] 68-68: Unexpected usage of doublequote. jsx-quotes [error] 69-69: Replace [error] 69-69: Unexpected usage of doublequote. jsx-quotes [error] 72-72: Insert 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
console.log, fix formatting, and movehandleResizeinsideuseEffect.Multiple pipeline-failing issues here:
console.log("resized")is a debug artifact — the linter rejects it (no-console).quotesrule).handleResizein the component body means a new reference is created each render, yet it's omitted from theuseEffectdeps. Move it inside the effect to keep the closure tight and avoid the stale-reference concern.Proposed fix (move handler into useEffect)
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