Skip to content

Solved the broken progress bar issue#226

Merged
mehul-m-prajapati merged 2 commits into
GitMetricsLab:mainfrom
Shayan-Bhowmik:NavBar/Progress-Bar
May 17, 2026
Merged

Solved the broken progress bar issue#226
mehul-m-prajapati merged 2 commits into
GitMetricsLab:mainfrom
Shayan-Bhowmik:NavBar/Progress-Bar

Conversation

@Shayan-Bhowmik
Copy link
Copy Markdown
Contributor

@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 initializes and updates immediately on load and correctly handles pages with no scrollable content.
  • Style

    • Updated progress bar appearance: reduced height, changed color to blue (#3b82f6), and refined the width transition timing for smoother updates.

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 99085ff
🔍 Latest deploy log https://app.netlify.com/projects/github-spy/deploys/6a0961d9f89b6c0008cdd48a
😎 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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dc07123a-1300-488d-87c4-ab9348badfdb

📥 Commits

Reviewing files that changed from the base of the PR and between b3bd7d8 and 99085ff.

📒 Files selected for processing (1)
  • src/components/ScrollProgressBar.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/ScrollProgressBar.tsx

📝 Walkthrough

Walkthrough

ScrollProgressBar extracts a shared handleScroll that computes clamped progress from document.documentElement, always attaches a scroll listener on mount (invoking it once immediately), and updates post-animation inline styles (height, color #3b82f6, and width transition timing).

Changes

Scroll Progress Bar Performance and Styling

Layer / File(s) Summary
Scroll progress calculation and listener simplification
src/components/ScrollProgressBar.tsx
Adds handleScroll to compute/clamp percentage from document.documentElement. Changes useEffect to always register the scroll listener on mount, call handleScroll() immediately for initial progress, and remove the listener on unmount.
Post-animation progress bar styling
src/components/ScrollProgressBar.tsx
Updates post-animation inline styles: decreases bar height, sets background color to #3b82f6, and adjusts the width transition duration/easing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I measured scrolls with nimble paws,
No more lag, no frozen laws.
A little bar, now slim and blue,
It follows scrolls both old and new.
Hooray — the page glides through!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change as fixing the progress bar issue, which aligns with the primary objective of the PR.
Description check ✅ Passed The description follows the repository template with all required sections completed: Related Issue, detailed Description, How Has This Been Tested, Type of Change, and optional Screenshots marked as N/A.
Linked Issues check ✅ Passed The PR addresses issue #222 by making the scroll progress bar responsive and smooth, eliminating scroll lag through immediate listener activation and proper initialization.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the ScrollProgressBar component's scroll tracking behavior and visual presentation; no unrelated modifications detected.
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
Contributor

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 thread src/components/ScrollProgressBar.tsx Outdated
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.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@mehul-m-prajapati mehul-m-prajapati merged commit f2e065a into GitMetricsLab:main May 17, 2026
6 checks passed
@github-actions
Copy link
Copy Markdown

🎉🎉 Thank you for your contribution! Your PR #226 has been merged! 🎉🎉

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The progress bar of the website

3 participants