Skip to content

Prevents page refresh and scroll-to-top on tab refocus #465

@Nofal71

Description

@Nofal71

#464

Hi, I have resolved the issue where pages (/, /projects, /mates) would reload and scroll to the top when the browser tab lost and regained focus.

The global useSWR hook in pages/_app.tsx (used for fetching user details) was re-fetching data on window focus by default. This triggered a re-render of the entire application, causing components to reset.

I disabled this behavior by adding revalidateOnFocus: false to the useSWR options in pages/_app.tsx. This maintains the page state and scroll position when switching tabs.

const { data: profileDetails, isLoading: isDetailsLoading } = useSWR(
getUserDetailsApiUrl,
fetcher,
{
errorRetryCount: 0,
revalidateOnFocus: false, // Add this line
}
);

after fix: https://drive.google.com/file/d/15woO0827VgC061wnJj3YEW9F1RWq9I8t/view?usp=drivesdk

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions