Skip to content

fix: start each navigation at the top of the page - #363

Open
arbrandes wants to merge 1 commit into
openedx:mainfrom
arbrandes:arbrandes/scroll-restoration
Open

arbrandes wants to merge 1 commit into
openedx:mainfrom
arbrandes:arbrandes/scroll-restoration

Conversation

@arbrandes

Copy link
Copy Markdown
Contributor

Description

This is the scroll half of #318. The shell runs a React Router data router but never rendered <ScrollRestoration />, and a data router leaves the scroll position alone without it. So moving between pages without a reload, starting from a page you'd scrolled down, landed you halfway down the next one, in every app.

It's now rendered once, in the root route's component, shell/Shell.tsx, which fixes it for all apps at once. Each new navigation starts at the top, and back/forward puts you back where you were.

The catch: a navigation that only rewrites the address, like a filter in the query string, now also jumps to the top unless it passes preventScrollReset. frontend-base's own code has none of those: its only navigate() call is the masquerade redirect, which goes to a different tab and should reset. Apps might, though, so there's a short note in the migration how-to, and converted apps that keep filters or pagination in the query string should add the option before they pick this up. Learning already does, in openedx/frontend-app-learning#2267.

The pending-navigation indicator, the other half of #318, is left for a later PR.

LLM usage notice

Built with assistance from Claude.

Client-side navigations no longer keep the previous page's scroll position, and back/forward restores it.

Part of openedx#318.

Co-Authored-By: Claude <noreply@anthropic.com>
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.

1 participant