From 0dfd597040720ac81374985eb5d98cfbb4f57593 Mon Sep 17 00:00:00 2001 From: Faakhir30 Date: Mon, 9 Dec 2024 02:30:26 +0500 Subject: [PATCH] update: skip scroll to top on inital SSR completion. Signed-off-by: Faakhir30 --- .../src/helpers/ScrollToTop/ScrollToTop.jsx | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/volto/src/helpers/ScrollToTop/ScrollToTop.jsx b/packages/volto/src/helpers/ScrollToTop/ScrollToTop.jsx index 8122fbea637..e938912c053 100644 --- a/packages/volto/src/helpers/ScrollToTop/ScrollToTop.jsx +++ b/packages/volto/src/helpers/ScrollToTop/ScrollToTop.jsx @@ -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. @@ -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