Skip to content

Commit

Permalink
added news.
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 e698d56
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/volto/news/6523.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disable initial scroll to top after SSR completion. @Faakhir30
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 e698d56

Please sign in to comment.