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

[docs] Fix navigation layout shift #35679

Merged

Conversation

oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Dec 31, 2022

The scroll position moves by 6 pixels each time you change page:

Screen.Recording.2022-12-31.at.12.52.39.mov

This regression was introduced between v4.12.4 and v5.0.0, e.g. https://v5-0-6.mui.com/components/typography/ KO, v4.12.4: OK https://v4.mui.com/components/radio-buttons/. It has been driving me crazy for over a year, it won't make it to 2023 (end of 2021: #29994 (comment)).

Why does this happen? Because Next.js REMOUNTs each page. This means that the CssBaseline that is inside the page gets unmounted, removes the boxSizing: 'border-box', style, which then means that the 3 diamond sponsors' 1px border is no longer taken into account in the height set, which means +6 pixels when this logic runs:

savedScrollTop[slot] = parent.scrollTop;


On a related note, in my video, it's fireworks when changing pages 🎆, the search bar blinks, the notification badge blinks, the sponsors blink. It also feels laggy. We could solve this by moving the main layout to _app.js so it rerenders, not remounts. However, this might lead to bundle size bloat to be able to support many different layouts (marketing, docs, template, blog, etc.). Maybe it's better to wait for: https://beta.nextjs.org/docs/routing/pages-and-layouts#layouts "A layout is UI that is shared between multiple pages".

@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work regression A bug, but worse scope: docs-infra Specific to the docs-infra product labels Dec 31, 2022
@mui-bot
Copy link

mui-bot commented Dec 31, 2022

Messages
📖 Netlify deploy preview: https://deploy-preview-35679--material-ui.netlify.app/

No bundle size changes

Generated by 🚫 dangerJS against d50c730

@oliviertassinari oliviertassinari added the docs Improvements or additions to the documentation label Dec 31, 2022
@oliviertassinari oliviertassinari merged commit 20ce1fc into mui:master Jan 12, 2023
@oliviertassinari oliviertassinari deleted the fix-layout-shift-navigation branch January 12, 2023 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work docs Improvements or additions to the documentation regression A bug, but worse scope: docs-infra Specific to the docs-infra product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants