Skip to content

WEBSITE-222 Investigate Page Jump#397

Open
SalazarJosh wants to merge 8 commits into
masterfrom
investigate-page-jump
Open

WEBSITE-222 Investigate Page Jump#397
SalazarJosh wants to merge 8 commits into
masterfrom
investigate-page-jump

Conversation

@SalazarJosh
Copy link
Copy Markdown
Collaborator

@SalazarJosh SalazarJosh commented Mar 4, 2026

Overview

If a user scrolls before hydration is complete, their scroll position is reset post-hydration. This causes a noticeable jump to the top of the page if the user scrolls before hydration is complete.

This pull request fixes WEBSITE-222.

The fix updates the shouldUpdateScroll() function to check if the old page path != the new page path before triggering the scroll reset. It also checks to the old page path against the new page path before putting focus on the H1 and triggering a jump back to the H1.

Testing

  • Make sure the PR is consistent in these browsers:
    • Chrome
    • Firefox
    • Safari
    • Edge (the assignee was not able to test the pull request in this browser)
  • Run accessibility tests:
    • WAVE
    • ARC Toolkit
    • axe DevTools

@SalazarJosh SalazarJosh changed the title testing to see if this is the culprit WEBSITE-222 Investigate Page Jump Mar 4, 2026
@SalazarJosh SalazarJosh requested a review from Copilot March 5, 2026 16:21
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 WEBSITE-222 by preventing scroll/focus side effects during initial hydration so users who scroll before hydration completes don’t get jumped back to the top / H1.

Changes:

  • Gate page-heading focus behavior in onRouteUpdate so it only runs on real client-side navigations (not initial hydration).
  • Update shouldUpdateScroll to avoid overriding restored scroll position on initial hydration and to skip scroll resets for hash URLs.

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

Comment thread gatsby-browser.js
Comment on lines +52 to 63
* with the location.hash check, so we return false if there's a hash in the URL.
*/

export const shouldUpdateScroll = ({ prevRouterProps, routerProps: { location } }) => {
if (!prevRouterProps) {
return false;
}

if (location.hash) {
return false;
}

Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

shouldUpdateScroll now skips scrolling on initial hydration and hash URLs, but it still calls window.scrollTo(0, 0) for any other route update. That includes query-string-only navigations where pathname is unchanged (e.g., staff directory / specialist filters update the URL via navigate('?…', { state: { preserveScroll: true } })). This contradicts the PR description (“check old page path != new page path”) and can reintroduce scroll resets during in-page searches/filters.

Consider comparing prevRouterProps.location.pathname vs routerProps.location.pathname (and/or honoring routerProps.location.state?.preserveScroll) before calling window.scrollTo so same-path URL updates don’t force a jump to the top.

Suggested change
* with the location.hash check, so we return false if there's a hash in the URL.
*/
export const shouldUpdateScroll = ({ prevRouterProps, routerProps: { location } }) => {
if (!prevRouterProps) {
return false;
}
if (location.hash) {
return false;
}
* with the location.hash check, so we return false if there's a hash in the URL.
* Additionally, avoid forcing scroll-to-top when only the query string changes
* (same pathname) or when the navigation explicitly opts out via
* location.state.preserveScroll.
*/
export const shouldUpdateScroll = ({ prevRouterProps, routerProps: { location } }) => {
// Don't interfere with the browser's initial scroll restoration.
if (!prevRouterProps) {
return false;
}
// Let hash-based scrolling be handled in onRouteUpdate.
if (location.hash) {
return false;
}
// Honor explicit request to preserve scroll position.
if (location.state && location.state.preserveScroll) {
return false;
}
const prevPathname =
prevRouterProps.location && prevRouterProps.location.pathname;
const nextPathname = location && location.pathname;
// Don't scroll to top if the pathname hasn't changed (e.g., query-string-only updates).
if (prevPathname === nextPathname) {
return false;
}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. Typing anything in our search causes a URL update and refresh. Open a pull request with the suggested change. @copilot

@SalazarJosh SalazarJosh marked this pull request as ready for review March 5, 2026 18:12
Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 5, 2026

@SalazarJosh I've opened a new pull request, #398, to work on those changes. Once the pull request is ready, I'll request review from you.

@SalazarJosh SalazarJosh self-assigned this Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants