Closed zbraniecki closed 1 year ago
This behavior is expected.
During navigation, everything within the page.tsx
file is unmounted. If you wish to maintain state (or in this instance, maintain the animation), the buttons "Item 1" and "Item 2" should reside in the layout.tsx
file. Layouts do not unmount when different URLs for the same navigation fragment are rendered.
Refer to the Next.js documentation for more details:
When navigating from /dashboard/settings to /dashboard/analytics, page.tsx in /dashboard/analytics will be rendered on the server because it is UI that changed, while dashboard/layout.tsx will not be re-rendered because it is a common UI between the two routes.
Based on the Next.js directory semantics, the content you render under "Item one" should be in the page.tsx
component. Meanwhile, all three buttons that alter the URL state should be in the layout.tsx
component.
It is common practice to use layout.tsx
for single page.tsx
file.
Thanks. I was able to reproduce the proper behavior with src/app/layout.tsx
.
But when I updated to subfolder src/app/foo/layout.tsx
I'm seeing the broken behavior again.
Here's the diff: https://github.com/zbraniecki/nextjs13-mui-tabs-navigation-demo/commit/c31e968e390cdd87c66c04be3e41fed5d28d3a2d
But when I updated to subfolder
src/app/foo/layout.tsx
I'm seeing the broken behavior again.
I've reviewed your setup and I'd like to point out a few adjustments that might resolve the issue based on the official documentation:
[[...id]]
, the layout.tsx
will be unmounted every time the parent path fragment params changes. Place your nested layout.tsx
in the 'foo' folderFor clarity, your directory structure should resemble the structure shown in the following screenshot:
Hi @rusted-love . Thanks for feedback. I applied the feedback and it still doesn't work.
My current suspicion is that src/app/layout.tsx
indeed doesn't reload on url change, but src/app/foo/layout.tsx
does reload even when the new url is leading to the same /foo/*
subdirectory.
@zbraniecki
I cloned your repository to the CodeSandbox. Everything works as expected. Tested with MacOS Safari and Google Chrome. Please take a look at CodeSandbox reproduction. Animation works as expected.
https://github.com/vercel/next.js/assets/32598874/e6eb16e4-f9b5-415b-a5ad-09c81acd6f4c
I can confirm that the latest version actually fixes my issue, both in minimized testcase and in actual app!
Thank you for your patience and support. Closing this issue.
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Link to the code that reproduces this issue or a replay of the bug
https://github.com/zbraniecki/nextjs13-mui-tabs-navigation-demo
To Reproduce
Current vs. Expected behavior
Currently, the tab switch animation breaks because the whole page reloads.\
Expected result is smooth animation, like in older version of Next
Verify canary release
Provide environment information
Which area(s) are affected? (Select all that apply)
Routing (next/router, next/navigation, next/link)
Additional context
I suspect that it has something to do with how nextjs 13 doesn't do shallow hydration on page navigation.