-
-
Notifications
You must be signed in to change notification settings - Fork 669
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
feat: optimize Banner Performance with Lazy Loading #3351
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThe Changes
Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
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.
✅ Deploy Preview for asyncapi-website ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-3351--asyncapi-website.netlify.app/ |
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.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (1)
components/campaigns/AnnouncementHero.tsx (1)
Line range hint
65-84
: Consider additional performance optimizationsWhile the lazy loading implementation reduces DOM nodes, the Lighthouse score indicates room for improvement. Consider these additional optimizations:
- Implement virtual scrolling or windowing using a library like
react-window
- Add
will-change
CSS property to optimize animations- Use CSS transform instead of DOM manipulation for transitions
Would you like me to provide example implementations for any of these suggestions?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
components/campaigns/AnnouncementHero.tsx
(2 hunks)
🧰 Additional context used
🪛 eslint
components/campaigns/AnnouncementHero.tsx
[error] 84-84: Insert ····
(prettier/prettier)
🔇 Additional comments (1)
components/campaigns/AnnouncementHero.tsx (1)
Line range hint 65-84
: Verify performance impact with React DevTools
The current implementation might still cause unnecessary re-renders of hidden banners.
Let's analyze the component's render behavior:
Consider wrapping the Banner component with React.memo to prevent unnecessary re-renders:
const MemoizedBanner = React.memo(Banner);
// Only render active banner and immediate neighbors | ||
const isVisible = Math.abs(index - (activeIndex % numberOfVisibleBanners)) <= 1; | ||
if (!isVisible) return null; |
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.
🛠️ Refactor suggestion
Improve code readability with a dedicated visibility check function
The visibility calculation logic could be more maintainable and self-documenting.
Consider extracting the visibility logic:
+ const isBannerVisible = (index: number, activeIndex: number, total: number) => {
+ const normalizedIndex = activeIndex % total;
+ return Math.abs(index - normalizedIndex) <= 1;
+ };
{visibleBanners.map((banner, index) => {
- const isVisible = Math.abs(index - (activeIndex % numberOfVisibleBanners)) <= 1;
+ const isVisible = isBannerVisible(index, activeIndex, numberOfVisibleBanners);
if (!isVisible) return null;
📝 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.
// Only render active banner and immediate neighbors | |
const isVisible = Math.abs(index - (activeIndex % numberOfVisibleBanners)) <= 1; | |
if (!isVisible) return null; | |
const isBannerVisible = (index: number, activeIndex: number, total: number) => { | |
const normalizedIndex = activeIndex % total; | |
return Math.abs(index - normalizedIndex) <= 1; | |
}; | |
// Only render active banner and immediate neighbors | |
const isVisible = isBannerVisible(index, activeIndex, numberOfVisibleBanners); | |
if (!isVisible) return null; |
89a3ea7
to
98e6c72
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3351 +/- ##
=======================================
Coverage 67.77% 67.77%
=======================================
Files 21 21
Lines 664 664
=======================================
Hits 450 450
Misses 214 214 ☔ View full report in Codecov by Sentry. |
The banner isn't visible altogether. Check out the netlify deploy above. |
Optimizes banner rendering performance to improve the Lighthouse score by implementing lazy loading for inactive banners. Only renders the active banner and immediate neighbors instead of all banners at once.
Before:
After:
Changes:
solves this issue
Summary by CodeRabbit
New Features
Bug Fixes