Skip to content

Commit

Permalink
update: skip scroll to top on inital SSR completion.
Browse files Browse the repository at this point in the history
Signed-off-by: Faakhir30 <[email protected]>
  • Loading branch information
Faakhir30 committed Dec 8, 2024
1 parent cfea4d9 commit 0dfd597
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/volto/src/helpers/ScrollToTop/ScrollToTop.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import config from '@plone/volto/registry';
* @extends {Component}
*/
class ScrollToTop extends React.Component {
constructor(props) {
super(props);
this.isClientSide = false;
this.isFirstClientUpdatePending = true;
}

/**
* Property types.
* @property {Object} propTypes Property types.
Expand All @@ -22,12 +28,30 @@ class ScrollToTop extends React.Component {
children: PropTypes.node.isRequired,
};

/**
* Used to indicate client-side rendering
* @memberof ScrollToTop
*/
componentDidMount() {
this.isClientSide = true;
}

/**
* @param {*} prevProps Previous Props
* @returns {null} Null
* @memberof ScrollToTop
*/
componentDidUpdate(prevProps) {
// avoid scrollToTop during SSR
if (!this.isClientSide) {
return;
}
// Skip the first client-side update that happens right after hydration
if (this.isFirstClientUpdatePending) {
this.isFirstClientUpdatePending = false;
return;
}

const { location } = this.props;
const noInitialBlocksFocus = // Do not scroll on /edit
config.blocks?.initialBlocksFocus === null
Expand Down

0 comments on commit 0dfd597

Please sign in to comment.