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

CLS in navbar during page change #2

Open
BretHudson opened this issue Feb 20, 2022 · 3 comments
Open

CLS in navbar during page change #2

BretHudson opened this issue Feb 20, 2022 · 3 comments

Comments

@BretHudson
Copy link

BretHudson commented Feb 20, 2022

CleanShot.2022-02-20.at.08.27.19.mp4

The navbar is experiencing CLS on page change. The source of this FOUC seems to be that the light/dark mode toggle is not visible during the initial render of a new page.

There are a few approaches to fixing this. Let me know if you have any questions!

@thienjs
Copy link
Owner

thienjs commented Feb 20, 2022

yea. I started noticing the flash. I thought it was because of framer-motion. I would love your help on fixing this. Thank you so much.

@BretHudson
Copy link
Author

Without looking at your code, I would assume there's something causing the toggle to only render after it is mounted. Due to this, when the toggle component is mounted, it adds it to the DOM and the navbar's flex recalculates to accommodate the newly placed element.

One simple solution would be to put a dummy icon/empty div in place of the toggle with the size of the icon when it hasn't yet been mounted, to "reserve" that space in the DOM before the actual toggle gets rendered.

I also just updated the title because I'm realizing it's not FOUC but CLS.

@BretHudson BretHudson changed the title FOUC on page change in navbar CLS in navbar during page change Feb 20, 2022
@thienjs
Copy link
Owner

thienjs commented Mar 1, 2022

Hey Bret, I tried a few things. This is what I came up with for now. Let me know what you think. Thank you so much for the help.

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

No branches or pull requests

2 participants