From 7fe2a9891d49a94df978f971c8efff20dc9f5db6 Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Tue, 29 Jun 2021 16:31:25 +0300 Subject: [PATCH] fix(v2): restore previous scroll position on back button click (#5081) --- .../src/theme/SkipToContent/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-theme-classic/src/theme/SkipToContent/index.tsx b/packages/docusaurus-theme-classic/src/theme/SkipToContent/index.tsx index d13943c02ad9..75dfe49c9222 100644 --- a/packages/docusaurus-theme-classic/src/theme/SkipToContent/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/SkipToContent/index.tsx @@ -6,6 +6,7 @@ */ import React, {useRef} from 'react'; +import {useHistory} from '@docusaurus/router'; import Translate from '@docusaurus/Translate'; import {useLocationChange} from '@docusaurus/theme-common'; @@ -19,6 +20,7 @@ function programmaticFocus(el: HTMLElement) { function SkipToContent(): JSX.Element { const containerRef = useRef(null); + const {action} = useHistory(); const handleSkip = (e: React.MouseEvent) => { e.preventDefault(); @@ -32,7 +34,7 @@ function SkipToContent(): JSX.Element { }; useLocationChange(({location}) => { - if (containerRef.current && !location.hash) { + if (containerRef.current && !location.hash && action !== 'POP') { programmaticFocus(containerRef.current); } });