-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
[Bug]: React. Lazy() combined with Outlet causes extra rendering of parent component #8930
Comments
This is expected behavior. You're wrapping everything in Suspense, which is swapping out the entire tree for your Fallback component while anything underneath it is suspended. |
|
Don't wrap everything in suspense, see this example: react-router/examples/lazy-loading/src/App.tsx Lines 42 to 46 in 2ee81d7
|
@timdorr but why not rerender again when page not refresh but switch to b from a ? b is also lazy component |
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
What version of React Router are you using?
6
Steps to Reproduce
question: React. Lazy() combined with Outlet causes extra rendering of parent component。
version: 6。
example:
describe:
If the current access URL is /a or /b, refreshing the browser will print "parent" twice because the component uses React.lazy().
If the current access URL is /c or /d, refreshing the browser will only print "parent" once, because the component is imported normally.
expect: to execute parent only once when React.lazy() is used
Expected Behavior
to execute parent only once when React.lazy() is used
Actual Behavior
If the current access URL is /a or /b, refreshing the browser will print "parent" twice because the component uses React.lazy().
If the current access URL is /c or /d, refreshing the browser will only print "parent" once, because the component is imported normally.
The text was updated successfully, but these errors were encountered: