gatsby-react-router-scroll is a Gatsby plugin designed to manage scroll behavior across page transitions, specifically within Gatsby applications that leverage `@reach/router`. It is a direct fork of `react-router-scroll`, which itself was an adaptation for React Router v4 from an earlier version, and has been further modified to be compatible with Gatsby's internal `@reach/router` usage. The current stable version is 6.16.0. As a utility tightly integrated with Gatsby, its release cadence generally aligns with Gatsby's main releases, typically seeing monthly minor updates and frequent patch releases. Its primary differentiation is its tight integration and optimization for the Gatsby ecosystem and its `@reach/router` dependency, providing a seamless scroll restoration experience without requiring extensive manual intervention, which is crucial for modern single-page application (SPA) navigation patterns.
npm install gatsby-react-router-scrollVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to integrate `gatsby-react-router-scroll` into a Gatsby project using the `wrapPageElement` browser API to manage scroll restoration across page transitions.
Ensure your project uses Gatsby's `@gatsbyjs/reach-router` internally. This plugin is not intended for use with standalone `react-router-dom` setups. Upgrading Gatsby to a compatible version (v4+) will generally provide the correct `@reach/router` environment.
Ensure your Node.js environment is within the supported range for Gatsby v5 (currently `>=18.0.0 <26.0.0`). Utilize tools like `nvm` or `volta` to manage and switch between Node.js versions effectively.
For highly dynamic content, consider manually triggering scroll updates (e.g., using `window.scrollTo(x, y)` or a custom `useEffect` hook) after asynchronous data or components have rendered. Adjusting the `timeout` prop on `ScrollManager` may help in some cases but is not a universal solution.
Review your `gatsby-browser.js` and other project dependencies to ensure only one scroll restoration mechanism is active. This plugin is designed to be the primary scroll manager for Gatsby's internal routing.
Ensure you are passing `location={props.location}` and `action={props.action}` directly to the `ScrollManager` within your `gatsby-browser.js` `wrapPageElement` export.Upgrade your Node.js version to one compatible with Gatsby v5 (e.g., Node.js 20 or 22). Use `nvm install 20 && nvm use 20` or similar version management commands.
Verify that your `wrapPageElement` function in `gatsby-browser.js` always returns the `ScrollManager` component with `element` as its child, like `return (<ScrollManager>{element}</ScrollManager>);`