Skip to content

Commit fca457c

Browse files
committed
fix: preserve deep-link anchors on privacy/terms pages
Scroll-to-top now checks window.location.hash first, so URLs like /privacy#section jump to the anchor instead of being overridden.
1 parent 54cff7a commit fca457c

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/components/LegalDocument.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import LanguageSwitcher from './LanguageSwitcher';
1818
*/
1919
function LegalDocument({ title, lastUpdated, sections }) {
2020
useEffect(() => {
21-
window.scrollTo(0, 0);
21+
if (!window.location.hash) {
22+
window.scrollTo(0, 0);
23+
}
2224
}, []);
2325

2426
return (

src/components/LegalDocument.test.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ describe('LegalDocument', () => {
6868
expect(screen.getByTestId('legal-footer')).toBeInTheDocument();
6969
});
7070

71+
it('scrolls to top when no hash fragment is present', () => {
72+
renderLegalDocument();
73+
expect(window.scrollTo).toHaveBeenCalledWith(0, 0);
74+
});
75+
76+
it('preserves scroll position when a hash fragment is present', () => {
77+
window.location.hash = '#intro';
78+
renderLegalDocument();
79+
expect(window.scrollTo).not.toHaveBeenCalled();
80+
window.location.hash = '';
81+
});
82+
7183
it('links back to the home page', () => {
7284
renderLegalDocument();
7385

0 commit comments

Comments
 (0)