-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[polaris.shopify.com] Fix next.js rehydration issue #7922
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
Conversation
kyledurand
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, didn't tophat but put some recommendations on a11y improvements
| {isMounted && ( | ||
| <button className={styles.DarkModeToggle} onClick={darkMode.toggle}> | ||
| {darkMode.value ? ( | ||
| <span className={styles.LightModeIcon}>💡</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <span className={styles.LightModeIcon}>💡</span> | |
| <span className={styles.LightModeIcon} role="img" aria-label="toggle light mode">💡</span> |
| {darkMode.value ? ( | ||
| <span className={styles.LightModeIcon}>💡</span> | ||
| ) : ( | ||
| <span className={styles.DarkModeIcon}>🌙</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <span className={styles.DarkModeIcon}>🌙</span> | |
| <span className={styles.DarkModeIcon} role="img" aria-label="toggle dark mode">🌙</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tophatted locally and can confirm the errors go away 💯 🌟
Sweet! Thanks, Lo! 🚀 |
Fixes this annoying message in development: <img width="1011" alt="image" src="https://user-images.githubusercontent.com/875708/207904298-8ebb19c3-3b9d-43cf-8a1a-78939a3f6b1a.png"> It was caused by the dark mode switcher having different states between the server and the client, thus breaking rehydration. This fix ensures that the dark mode toggle is only rendered on the client.
Fixes this annoying message in development:
It was caused by the dark mode switcher having different states between the server and the client, thus breaking rehydration. This fix ensures that the dark mode toggle is only rendered on the client.