Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Previous page re-rendered when navigate to the other when using defer, useLoaderData [Bug]: #10756

Closed
TonyFTannous opened this issue Aug 2, 2023 · 1 comment
Labels

Comments

@TonyFTannous
Copy link

What version of React Router are you using?

6.14.2

Steps to Reproduce

I use useLoaderData, defer and Suspense/await ...

when i navigate from secreen to other, the previous one re-rendered, why??? is it normal and how can i prevent the current screen from re-rendered when i navigate to other

thanks

Expected Behavior

When i navigate from secreen to other, the previous one re-rendered

Actual Behavior

Prevent the current screen from re-rendered when i navigate to other

@TonyFTannous TonyFTannous changed the title Previous page rerendered when navigate to the other when using defer, useLoaderData [Bug]: Previous page re-rendered when navigate to the other when using defer, useLoaderData [Bug]: Aug 2, 2023
@brophdawg11
Copy link
Contributor

This is expected behavior. When you navigate, React Router updates useNavigation().state from idle to loading and remains on the current page while the loaders run for the next page. This causes the current page to re-render so that it can show any pending/optimistic UI based on useNavigation().

Re-renders are at the heart of React and are usually not an issue unless you have expensive/slow components, and you can optimize them individually if they are problematic: https://kentcdodds.com/blog/fix-the-slow-render-before-you-fix-the-re-render

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants