Skip to content

Solved the broken progress bar issue#226

Open
Shayan-Bhowmik wants to merge 1 commit into
GitMetricsLab:mainfrom
Shayan-Bhowmik:NavBar/Progress-Bar
Open

Solved the broken progress bar issue#226
Shayan-Bhowmik wants to merge 1 commit into
GitMetricsLab:mainfrom
Shayan-Bhowmik:NavBar/Progress-Bar

Conversation

@Shayan-Bhowmik
Copy link
Copy Markdown

@Shayan-Bhowmik Shayan-Bhowmik commented May 12, 2026

Related Issue


Description

I've fixed the scroll progress bar functionality on the navbar. The progress bar had several issues that prevented it from working properly:

  1. Scroll listener delay - The scroll event listener was only being added after the 2-second page load animation completed, so it missed tracking scroll changes during that time
  2. No initial position - The scroll progress width wasn't being calculated on component mount, so users wouldn't see progress until they actually scrolled
  3. Poor visibility - The grey color was difficult to see against the navbar background

I've resolved these by:

  • Activating the scroll listener immediately on component mount
  • Calling handleScroll() on mount to capture the initial scroll position
  • Changing the color to a more visible blue (#3b82f6)
  • Improving the transition smoothness (0.1s instead of 0.2s)

How Has This Been Tested?

I've manually tested by:

  • Scrolling up and down the page to verify the blue progress bar fills proportionally
  • Checking that the bar starts tracking immediately on page load
  • Verifying the initial 2-second animation still displays correctly before switching to scroll tracking

Screenshots (if applicable)

N/A


Type of Change

  • Bug fix
  • New feature
  • Code style update
  • Breaking change
  • Documentation update

Summary by CodeRabbit

  • Bug Fixes

    • Scroll progress bar now responds immediately when the page loads.
  • Style

    • Updated scroll progress bar appearance: reduced height, changed color to blue, and adjusted animation timing.

Review Change Stack

Copilot AI review requested due to automatic review settings May 12, 2026 16:29
@netlify
Copy link
Copy Markdown

netlify Bot commented May 12, 2026

Deploy Preview for github-spy ready!

Name Link
🔨 Latest commit b3bd7d8
🔍 Latest deploy log https://app.netlify.com/projects/github-spy/deploys/6a03556d5b984500085a3df2
😎 Deploy Preview https://deploy-preview-226--github-spy.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
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

📝 Walkthrough

Walkthrough

ScrollProgressBar refactors scroll event handling to improve performance by eliminating conditional listener attachment and replacing it with unconditional mount-time registration. A new handleScroll function calculates and updates progress state. Post-animation styling is updated with adjusted height, color, and transition timing.

Changes

Scroll Progress Bar Performance and Styling

Layer / File(s) Summary
Scroll progress calculation and listener simplification
src/components/ScrollProgressBar.tsx
handleScroll function computes scroll progress from document scroll position. The useEffect is simplified to always register the scroll listener on mount (not conditional on isAnimating), call handleScroll once to set initial progress, and remove the listener on unmount. Post-animation progress bar styling updates the line height, color to blue hex, and width transition duration/easing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit hops through scroll events now,
No animation delays, I vow!
Progress bars glide smooth and fast,
The lag is gone at last—
Blue lines that dance with every click! 🎨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Solved the broken progress bar issue' clearly and specifically describes the main change—fixing the scroll progress bar functionality.
Description check ✅ Passed The description comprehensively covers all required template sections: linked issue, detailed description of problems and solutions, testing approach, and type of change selection.
Linked Issues check ✅ Passed The PR successfully addresses issue #222's objective to eliminate lag and make the progress bar responsive by immediately registering scroll listeners, calculating initial position, improving visibility, and optimizing transition timing.
Out of Scope Changes check ✅ Passed All changes in ScrollProgressBar.tsx are directly scoped to fixing the progress bar lag and responsiveness issues outlined in issue #222; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes the navbar scroll progress indicator so it updates immediately and displays with improved visibility/smoothness.

Changes:

  • Register the scroll event listener on mount (instead of waiting for the 2s load animation to finish)
  • Initialize progress state by calling handleScroll() on mount
  • Update progress bar styling (color, height, transition timing)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +8 to +12
const scrollTop = document.documentElement.scrollTop;
const scrollHeight =
document.documentElement.scrollHeight -
document.documentElement.clientHeight;
const width = (scrollTop / scrollHeight) * 100;
Comment on lines +7 to +14
const handleScroll = () => {
const scrollTop = document.documentElement.scrollTop;
const scrollHeight =
document.documentElement.scrollHeight -
document.documentElement.clientHeight;
const width = (scrollTop / scrollHeight) * 100;
setScrollWidth(width);
};
Comment on lines 26 to 31
useEffect(() => {
if (!isAnimating) {
window.addEventListener("scroll", handleScroll);
}
// Always listen for scroll events
window.addEventListener("scroll", handleScroll);
// Call handleScroll once on mount to set initial position
handleScroll();
return () => window.removeEventListener("scroll", handleScroll);
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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/ScrollProgressBar.tsx`:
- Around line 7-14: The handleScroll function can produce NaN when
document.documentElement.scrollHeight - document.documentElement.clientHeight is
0 and is recreated each render, breaking cleanup; wrap handleScroll in
useCallback and inside it compute denom = document.documentElement.scrollHeight
- document.documentElement.clientHeight, if denom === 0 setScrollWidth(0) else
setScrollWidth((scrollTop / denom) * 100); then use that same memoized
handleScroll in the effect that adds/removes the 'scroll' listener (include
handleScroll in the effect deps) so addEventListener and removeEventListener
receive the identical function reference.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fc05cfaa-23db-4282-96d8-0b4073953ec8

📥 Commits

Reviewing files that changed from the base of the PR and between 56e17a3 and b3bd7d8.

📒 Files selected for processing (1)
  • src/components/ScrollProgressBar.tsx

Comment on lines +7 to +14
const handleScroll = () => {
const scrollTop = document.documentElement.scrollTop;
const scrollHeight =
document.documentElement.scrollHeight -
document.documentElement.clientHeight;
const width = (scrollTop / scrollHeight) * 100;
setScrollWidth(width);
};
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 | 🔴 Critical | ⚡ Quick win

Guard against division by zero and wrap in useCallback.

Two issues:

  1. When page content fits on screen without scrolling, scrollHeight - clientHeight equals 0, causing width to become NaN and breaking the progress bar rendering.

  2. The function is recreated on every render. The cleanup at line 31 attempts to remove a different function reference than was registered at line 28, preventing proper cleanup and causing a memory leak.

🔧 Proposed fix
-import { useEffect, useState } from "react";
+import { useCallback, useEffect, useState } from "react";
...
-  const handleScroll = () => {
+  const handleScroll = useCallback(() => {
     const scrollTop = document.documentElement.scrollTop;
     const scrollHeight =
       document.documentElement.scrollHeight -
       document.documentElement.clientHeight;
+    
+    // Guard against division by zero when content doesn't scroll
+    if (scrollHeight === 0) {
+      setScrollWidth(0);
+      return;
+    }
+    
     const width = (scrollTop / scrollHeight) * 100;
     setScrollWidth(width);
-  };
+  }, []);
📝 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 handleScroll = () => {
const scrollTop = document.documentElement.scrollTop;
const scrollHeight =
document.documentElement.scrollHeight -
document.documentElement.clientHeight;
const width = (scrollTop / scrollHeight) * 100;
setScrollWidth(width);
};
const handleScroll = useCallback(() => {
const scrollTop = document.documentElement.scrollTop;
const scrollHeight =
document.documentElement.scrollHeight -
document.documentElement.clientHeight;
// Guard against division by zero when content doesn't scroll
if (scrollHeight === 0) {
setScrollWidth(0);
return;
}
const width = (scrollTop / scrollHeight) * 100;
setScrollWidth(width);
}, []);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/ScrollProgressBar.tsx` around lines 7 - 14, The handleScroll
function can produce NaN when document.documentElement.scrollHeight -
document.documentElement.clientHeight is 0 and is recreated each render,
breaking cleanup; wrap handleScroll in useCallback and inside it compute denom =
document.documentElement.scrollHeight - document.documentElement.clientHeight,
if denom === 0 setScrollWidth(0) else setScrollWidth((scrollTop / denom) * 100);
then use that same memoized handleScroll in the effect that adds/removes the
'scroll' listener (include handleScroll in the effect deps) so addEventListener
and removeEventListener receive the identical function reference.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The progress bar of the website

2 participants