Skip to content

Commit

Permalink
fix: scroll to top on navigating between routes
Browse files Browse the repository at this point in the history
  • Loading branch information
seanes committed Feb 26, 2025
1 parent f70617c commit ed2846f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/frontend/src/components/PageLayout/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
} from '@altinn/altinn-components';
import { Snackbar } from '@altinn/altinn-components';
import { useQueryClient } from '@tanstack/react-query';
import { type ChangeEvent, useEffect } from 'react';
import { type ChangeEvent, useEffect, useLayoutEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { Link, Outlet, useSearchParams } from 'react-router-dom';
import { Link, Outlet, useLocation, useSearchParams } from 'react-router-dom';
import { useDialogs } from '../../api/useDialogs.tsx';
import { useParties } from '../../api/useParties.ts';
import { getSearchStringFromQueryParams } from '../../pages/Inbox/queryParams.ts';
Expand Down Expand Up @@ -76,6 +76,13 @@ export const PageLayout: React.FC = () => {

useProfile();

const location = useLocation();

// biome-ignore lint/correctness/useExhaustiveDependencies: runs synchronously after DOM mutations but before the browser paints.
useLayoutEffect(() => {
window.scrollTo({ top: 0, left: 0, behavior: 'instant' });
}, [location.pathname]);

// biome-ignore lint/correctness/useExhaustiveDependencies: Full control of what triggers this code is needed
useEffect(() => {
const searchString = getSearchStringFromQueryParams(searchParams);
Expand Down

0 comments on commit ed2846f

Please sign in to comment.