Skip to content

Add ScrollToTop component for resetting scroll position#62

Merged
hoangsonww merged 1 commit into
masterfrom
feat/enhance-FE
May 31, 2026
Merged

Add ScrollToTop component for resetting scroll position#62
hoangsonww merged 1 commit into
masterfrom
feat/enhance-FE

Conversation

@hoangsonww

Copy link
Copy Markdown
Owner

No description provided.

@hoangsonww hoangsonww added this to the v2.x.x - Enhanced Release milestone May 31, 2026
@hoangsonww hoangsonww self-assigned this May 31, 2026
Copilot AI review requested due to automatic review settings May 31, 2026 08:25
@hoangsonww hoangsonww added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels May 31, 2026
@netlify

netlify Bot commented May 31, 2026

Copy link
Copy Markdown

Deploy Preview for docuthinker-ai-app ready!

Name Link
🔨 Latest commit 1e982da
🔍 Latest deploy log https://app.netlify.com/projects/docuthinker-ai-app/deploys/6a1bf0850767b3000846252f
😎 Deploy Preview https://deploy-preview-62--docuthinker-ai-app.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 26
Accessibility: 91
Best Practices: 92
SEO: 100
PWA: 80
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@vercel

vercel Bot commented May 31, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docuthinker-fullstack-app Ignored Ignored May 31, 2026 8:25am

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a ScrollToTop component in frontend/src/App.js to reset the scroll position to the top of the page on route changes. The reviewer recommends refining this behavior by using the useNavigationType hook from react-router-dom to prevent scrolling to the top during back/forward navigations (where the action is POP), thereby preserving the browser's native scroll restoration and improving user experience.

Comment thread frontend/src/App.js
Comment on lines +41 to +49
function ScrollToTop() {
const { pathname } = useLocation();

useEffect(() => {
window.scrollTo(0, 0);
}, [pathname]);

return null;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

When users navigate back or forward (using the browser's back/forward buttons), they expect their scroll position to be restored. Currently, ScrollToTop will force the page to scroll to the top on every route change, including back/forward navigations (which trigger a POP action). This overrides the browser's native scroll restoration and degrades the user experience.

To fix this, you can use the useNavigationType hook from react-router-dom to only scroll to the top when the navigation action is PUSH or REPLACE (i.e., not POP).

Note: Make sure to import useNavigationType from react-router-dom at the top of the file.

function ScrollToTop() {
  const { pathname } = useLocation();
  const navigationType = useNavigationType();

  useEffect(() => {
    if (navigationType !== "POP") {
      window.scrollTo(0, 0);
    }
  }, [pathname, navigationType]);

  return null;
}

@hoangsonww
hoangsonww merged commit 4c310f9 into master May 31, 2026
6 of 8 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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

Labels

bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants