Skip to content

Commit

Permalink
use prevProps instead of component state
Browse files Browse the repository at this point in the history
  • Loading branch information
Faakhir30 committed Dec 10, 2024
1 parent efa614d commit 292f75c
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions packages/volto/src/helpers/ScrollToTop/ScrollToTop.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,12 @@ class ScrollToTop extends React.Component {
children: PropTypes.node.isRequired,
};

state = {
isFirstClientUpdatePending: true,
};
/**
* @param {*} prevProps Previous Props
* @returns {null} Null
* @memberof ScrollToTop
*/
componentDidUpdate(prevProps) {
// Skip the first client-side update that happens right after hydration
if (this.state.isFirstClientUpdatePending) {
this.setState({ isFirstClientUpdatePending: false });
return;
}

const { location } = this.props;
const noInitialBlocksFocus = // Do not scroll on /edit
config.blocks?.initialBlocksFocus === null
Expand All @@ -46,6 +37,7 @@ class ScrollToTop extends React.Component {
const isHash = location?.hash || location?.pathname.hash;
if (
!isHash &&
prevProps.location !== undefined &&
noInitialBlocksFocus &&
location?.pathname !== prevProps.location?.pathname
) {
Expand Down

0 comments on commit 292f75c

Please sign in to comment.