Skip to content

Commit

Permalink
update: ssr detection logic and news filename.
Browse files Browse the repository at this point in the history
  • Loading branch information
Faakhir30 committed Dec 9, 2024
1 parent e698d56 commit 0c34913
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
File renamed without changes.
25 changes: 5 additions & 20 deletions packages/volto/src/helpers/ScrollToTop/ScrollToTop.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ 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 @@ -28,27 +22,18 @@ class ScrollToTop extends React.Component {
children: PropTypes.node.isRequired,
};

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

state = {
isFirstClientUpdatePending: 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;
if (this.state.isFirstClientUpdatePending) {
this.setState({ isFirstClientUpdatePending: false });
return;
}

Expand Down

0 comments on commit 0c34913

Please sign in to comment.