Skip to content

🐛 fix: reset scroll position to top on route change and fix lint issues#501

Merged
mehul-m-prajapati merged 2 commits into
GitMetricsLab:mainfrom
atharv96k:fix/scroll-to-top
May 29, 2026
Merged

🐛 fix: reset scroll position to top on route change and fix lint issues#501
mehul-m-prajapati merged 2 commits into
GitMetricsLab:mainfrom
atharv96k:fix/scroll-to-top

Conversation

@atharv96k
Copy link
Copy Markdown
Contributor

@atharv96k atharv96k commented May 25, 2026

Related Issue
Closes: #497

Description
Implemented a global ScrollToTop utility component that listens to navigation events using react-router-dom's useLocation hook. This ensures that the window viewport resets automatically to the top coordinates (0, 0) upon route changes, resolving the bug where navigating via footer quick links kept the user stuck at the bottom of the newly loaded page.

Additionally, resolved pre-existing strict linter errors (@typescript-eslint/no-unused-vars and @typescript-eslint/no-explicit-any) across Navbar.tsx, Navbar.test.tsx, useGitHubData.ts, and Signup.tsx to ensure npm run lint passes successfully.

How Has This Been Tested?
Manual testing: Navigated to the bottom of the page, clicked "About" and "Contact Us" links from the footer, and verified that the viewport automatically scrolls to the top.

Edge case testing: Scrolled down on the /about page and clicked the "About" link again; verified that it successfully scrolls to the top by tracking the full location object inside the useEffect dependency array.

Ran local verification checks: Executed npm run lint locally and confirmed that all errors have been resolved (0 errors remaining).

Type of Change
[x] Bug fix
[ ] New feature
[x] Code style update
[ ] Breaking change
[ ] Documentation update

Screenshots (if applicable)
GithubTracker-GoogleChrome2026-05-2512-44-05-ezgif com-video-to-gif-converter

Summary by CodeRabbit

  • New Features

    • Pages automatically scroll to the top of the page when navigating to different sections of the application.
  • Refactor

    • Enhanced error handling and messaging for signup form submissions and API requests.
    • Improved type safety annotations and optimized internal component structure for better code stability.

Review Change Stack

@netlify
Copy link
Copy Markdown

netlify Bot commented May 25, 2026

Deploy Preview for github-spy ready!

Name Link
🔨 Latest commit 540e9f4
🔍 Latest deploy log https://app.netlify.com/projects/github-spy/deploys/6a19c35742b6080008c43ac1
😎 Deploy Preview https://deploy-preview-501--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 25, 2026

Warning

Review limit reached

@mehul-m-prajapati, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 43 minutes and 44 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9d1a73e2-f8f4-4d9a-9631-32f58e4c237b

📥 Commits

Reviewing files that changed from the base of the PR and between 8063f23 and 540e9f4.

📒 Files selected for processing (4)
  • src/App.tsx
  • src/components/Navbar.tsx
  • src/hooks/useGitHubData.ts
  • src/pages/Signup/Signup.tsx
📝 Walkthrough

Walkthrough

This PR implements a fix for automatic page scroll-to-top on route navigation (addressing issue #497), improves Signup form error handling with safer TypeScript patterns, restructures form JSX for clarity, and tightens type annotations across the codebase. Six files are modified: ScrollToTop component is added and integrated into App.tsx, Signup error handling uses axios.isAxiosError for type-safe error extraction, form JSX is reformatted for readability, useGitHubData types improve from Promise to Promise, and minor icon/import cleanup in Navbar and tests.

Changes

Route Navigation and Form Quality Improvements

Layer / File(s) Summary
ScrollToTop component for automatic scroll-to-top on route changes
src/components/ScrollToTop.tsx, src/App.tsx
New ScrollToTop component uses useLocation to trigger window.scrollTo(0, 0) on every route change, imported into App and rendered near the top of the layout. Fixes the bug where pages remain at footer position after navigation.
Signup form error handling and validation improvements
src/pages/Signup/Signup.tsx
handleSubmit now treats errors as unknown and uses axios.isAxiosError type guard to safely extract error.response?.data?.message with generic fallback. handleChange password validation is reformatted for clarity.
Signup form UI layout restructuring
src/pages/Signup/Signup.tsx
Header (logo, title, subtitle), form fields (inputs with icons and inline errors), password visibility toggle, and message/login-link sections are reformatted into multiline JSX blocks. Conditional rendering and styling logic unchanged.
Type safety improvements in hooks and components
src/hooks/useGitHubData.ts, src/components/Navbar.tsx, src/components/__test__/Navbar.test.tsx
useGitHubData tightens requests array type from Promise<any>[] to Promise<unknown>[]. Navbar updates lucide-react imports to include X icon. Navbar test removes unused beforeEach import.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

gssoc25, level:intermediate, quality:clean

Poem

🐰 A scroll to the top, what a hop!
When navigating near and far,
No more stuck at the footer bar,
The ScrollToTop makes journeys bright,
Keeping pages in perfect sight! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: implementing scroll-to-top on route changes and fixing linting issues.
Description check ✅ Passed The description follows the template structure with all required sections completed: related issue, detailed description, testing methodology, and type of change.
Linked Issues check ✅ Passed The PR successfully implements all requirements from issue #497: ScrollToTop component with useLocation hook, automatic scroll on route changes, and comprehensive testing verification.
Out of Scope Changes check ✅ Passed All changes are within scope: ScrollToTop component addresses the bug, linter fixes resolve pre-existing errors mentioned in the PR objectives, and no unrelated modifications are present.

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

🎉 Thank you @atharv96k for your contribution. Please make sure your PR follows https://github.com/GitMetricsLab/github_tracker/blob/main/CONTRIBUTING.md#-pull-request-guidelines

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: 2

🧹 Nitpick comments (3)
src/components/Navbar.tsx (1)

4-4: 💤 Low value

Add spacing before closing brace in import statement.

The import statement is missing a space before the closing brace: X} should be X } for consistent formatting.

✨ Formatting fix
-import { Moon, Sun, Menu, X} from "lucide-react";
+import { Moon, Sun, Menu, X } from "lucide-react";
🤖 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/Navbar.tsx` at line 4, The import list in Navbar.tsx has
inconsistent spacing before the closing brace—update the import statement that
currently lists Moon, Sun, Menu, X to include a space before the closing brace
(change the token sequence ending with "X}" to "X }") so the import reads with
consistent spacing around braces for the symbols Moon, Sun, Menu, and X.
src/components/__test__/Navbar.test.tsx (1)

3-3: 💤 Low value

Add spacing before closing brace in import statement.

The import statement is missing a space before the closing brace: vi} should be vi } for consistent formatting.

✨ Formatting fix
-import { describe, it, expect, vi} from 'vitest'
+import { describe, it, expect, vi } from 'vitest'
🤖 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/__test__/Navbar.test.tsx` at line 3, The import line importing
describe, it, expect, and vi has no space before the closing brace; update the
import statement that lists the symbols (describe, it, expect, vi) so the
closing brace is spaced as "vi }" to match project formatting conventions.
src/hooks/useGitHubData.ts (1)

115-115: ⚡ Quick win

Avoid losing type info by typing requests as the fetchPaginated return type (src/hooks/useGitHubData.ts:115).

  • fetchPaginated returns { items: GitHubItem[]; total: number }, and tsc --noEmit succeeds, so the current .items/.total access is accepted.
  • Promise<unknown>[] unnecessarily erases that type; use the fetchPaginated return type instead (e.g., Promise<{ items: GitHubItem[]; total: number }>[] / ReturnType<typeof fetchPaginated>[]).
Proposed fix
-        const requests: Promise<unknown>[] = [];
+        const requests: Promise<{ items: GitHubItem[], total: number }>[] = [];
🤖 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/hooks/useGitHubData.ts` at line 115, The variable requests is currently
typed as Promise<unknown>[] which erases the actual shape returned by
fetchPaginated; change its type to the fetchPaginated return type (for example
Promise<{ items: GitHubItem[]; total: number }>[] or ReturnType<typeof
fetchPaginated>[] ) so callers that read .items and .total keep proper
types—update the declaration of requests in useGitHubData (variable name
requests) to use that precise return type.
🤖 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/pages/Signup/Signup.tsx`:
- Around line 200-212: The username input (and other fields using formData,
handleChange, errors and mode) lacks a programmatic label and proper ARIA error
association; add a <label htmlFor="username"> linked to the input's
id="username", set input's aria-describedby to an id for the error message
(e.g., username-error) and ensure the error <p> has that id plus role="alert"
and aria-live="assertive" so screen readers announce validation; repeat the same
pattern for email and password fields, keeping existing props
(value={formData...}, onChange={handleChange}, required) and preserving the
mode-based className logic.
- Around line 95-98: The comment "Include cookies for session" on the axios.post
in Signup.tsx is misleading because the call only passes url and formData;
either remove that comment or explicitly enable credentials: update the
axios.post call that sends formData to include an axios config with
withCredentials: true (or ensure a global axios default is set to
withCredentials: true) so cookies are actually sent; locate the axios.post
invocation in the Signup component and apply one of these two fixes to make the
behavior and comment consistent.

---

Nitpick comments:
In `@src/components/__test__/Navbar.test.tsx`:
- Line 3: The import line importing describe, it, expect, and vi has no space
before the closing brace; update the import statement that lists the symbols
(describe, it, expect, vi) so the closing brace is spaced as "vi }" to match
project formatting conventions.

In `@src/components/Navbar.tsx`:
- Line 4: The import list in Navbar.tsx has inconsistent spacing before the
closing brace—update the import statement that currently lists Moon, Sun, Menu,
X to include a space before the closing brace (change the token sequence ending
with "X}" to "X }") so the import reads with consistent spacing around braces
for the symbols Moon, Sun, Menu, and X.

In `@src/hooks/useGitHubData.ts`:
- Line 115: The variable requests is currently typed as Promise<unknown>[] which
erases the actual shape returned by fetchPaginated; change its type to the
fetchPaginated return type (for example Promise<{ items: GitHubItem[]; total:
number }>[] or ReturnType<typeof fetchPaginated>[] ) so callers that read .items
and .total keep proper types—update the declaration of requests in useGitHubData
(variable name requests) to use that precise return type.
🪄 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: e9c03e3f-75d6-4fcc-a7f5-9ac7d25b1063

📥 Commits

Reviewing files that changed from the base of the PR and between 6c6bc3e and 8063f23.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • src/App.tsx
  • src/components/Navbar.tsx
  • src/components/ScrollToTop.tsx
  • src/components/__test__/Navbar.test.tsx
  • src/hooks/useGitHubData.ts
  • src/pages/Signup/Signup.tsx

Comment on lines +95 to 98
const response = await axios.post(
`${backendUrl}/api/auth/signup`,
formData, // Include cookies for session
);
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 | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify whether credentials are already configured globally and compare auth request patterns.
rg -n -C3 'axios\.create\(|axios\.defaults\.withCredentials|withCredentials\s*:\s*true'
rg -n -C2 '/api/auth/signup|/api/auth/login|/api/auth'

Repository: GitMetricsLab/github_tracker

Length of output: 881


🏁 Script executed:

#!/bin/bash
set -euo pipefail
rg -n "withCredentials" -S .
rg -n "axios\.create\(" -S src backend .
rg -n "axios\.defaults\.withCredentials" -S src backend .
rg -n -C3 "Include cookies" src/pages/Signup/Signup.tsx
sed -n '70,120p' src/pages/Signup/Signup.tsx
sed -n '1,120p' src/pages/Login/Login.tsx
sed -n '1,120p' backend/server.js
ls -la src | head

Repository: GitMetricsLab/github_tracker

Length of output: 151


🏁 Script executed:

#!/bin/bash
set +euo pipefail
rg -n "withCredentials" -S src backend || true
rg -n "axios\.create\(" -S src backend || true
rg -n "axios\.defaults\.withCredentials" -S src backend || true
rg -n "axios\.defaults" -S src backend | head -n 50
sed -n '1,220p' src/pages/Signup/Signup.tsx
sed -n '1,140p' src/pages/Login/Login.tsx
fd -t f "axios*.ts" src backend -a || true
fd -t f -g "*axios*" src backend || true
rg -n "from 'axios'|require\\(['\"]axios['\"]\\)" -S src backend || true

Repository: GitMetricsLab/github_tracker

Length of output: 14360


Fix misleading cookies comment on signup axios request

src/pages/Signup/Signup.tsx’s /api/auth/signup axios.post only passes url and data; there’s no withCredentials (and no global axios credentials config found—only a withCredentials: false elsewhere). Either remove the “Include cookies for session” comment or add explicit axios config.

✅ If cookies are required for this route
 const response = await axios.post(
   `${backendUrl}/api/auth/signup`,
-  formData, // Include cookies for session
+  formData,
+  { withCredentials: true },
 );
🤖 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/pages/Signup/Signup.tsx` around lines 95 - 98, The comment "Include
cookies for session" on the axios.post in Signup.tsx is misleading because the
call only passes url and formData; either remove that comment or explicitly
enable credentials: update the axios.post call that sends formData to include an
axios config with withCredentials: true (or ensure a global axios default is set
to withCredentials: true) so cookies are actually sent; locate the axios.post
invocation in the Signup component and apply one of these two fixes to make the
behavior and comment consistent.

Comment on lines +200 to +212
<input
type="text"
name="username"
placeholder="Enter your username"
value={formData.username}
onChange={handleChange}
required
className={`w-full pl-12 pr-4 py-4 rounded-2xl border focus:outline-none focus:ring-2 focus:ring-gray-400 focus:border-transparent transition-all duration-300 ${mode === "dark" ? "bg-white/10 border-white/20 text-white placeholder-gray-400" : "bg-gray-100 border-gray-300 text-black placeholder-gray-400"}`}
/>
</div>
{errors.username && <p className="text-red-500 text-sm mt-2">{errors.username}</p>}
{errors.username && (
<p className="text-red-500 text-sm mt-2">{errors.username}</p>
)}
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 | ⚡ Quick win

Add explicit labels and error associations for all form fields.

The inputs rely on placeholders only. Please add programmatic labels (label + htmlFor) and connect inline errors with aria-describedby/role="alert" so screen-reader users get field context and validation feedback reliably.

♿ Suggested pattern (apply to username/email/password)
+ <label htmlFor="signup-username" className="sr-only">Username</label>
  <input
+   id="signup-username"
    type="text"
    name="username"
    placeholder="Enter your username"
    value={formData.username}
    onChange={handleChange}
    required
+   aria-invalid={Boolean(errors.username)}
+   aria-describedby={errors.username ? "signup-username-error" : undefined}
    className="..."
  />
- {errors.username && (
-   <p className="text-red-500 text-sm mt-2">{errors.username}</p>
- )}
+ {errors.username && (
+   <p id="signup-username-error" role="alert" className="text-red-500 text-sm mt-2">
+     {errors.username}
+   </p>
+ )}

Also applies to: 220-232, 240-265

🤖 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/pages/Signup/Signup.tsx` around lines 200 - 212, The username input (and
other fields using formData, handleChange, errors and mode) lacks a programmatic
label and proper ARIA error association; add a <label htmlFor="username"> linked
to the input's id="username", set input's aria-describedby to an id for the
error message (e.g., username-error) and ensure the error <p> has that id plus
role="alert" and aria-live="assertive" so screen readers announce validation;
repeat the same pattern for email and password fields, keeping existing props
(value={formData...}, onChange={handleChange}, required) and preserving the
mode-based className logic.

@mehul-m-prajapati mehul-m-prajapati merged commit 3aa656c into GitMetricsLab:main May 29, 2026
4 of 6 checks passed
@github-actions
Copy link
Copy Markdown

🎉🎉 Thank you for your contribution! Your PR #501 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.

🐛 Bug Report: Page does not scroll to top when navigating to /contact or /about via footer links

2 participants