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

useColorMode and useDark trigger reflows every time they are used #3955

Open
7 tasks done
jpleclerc opened this issue May 6, 2024 · 0 comments
Open
7 tasks done

useColorMode and useDark trigger reflows every time they are used #3955

jpleclerc opened this issue May 6, 2024 · 0 comments

Comments

@jpleclerc
Copy link

jpleclerc commented May 6, 2024

Describe the bug

The bug has two parts:

  1. useColorMode's default onChange function is triggered as soon as the composable is called. Unless the disableTransition: false option is used, the page will reflow and negatively impact performance on complex pages.
  2. The onChange function will be triggered once per useColorMode usage whenever we toggle the dark mode, triggering a reflow each time.

This also affects useDark since it directly uses useColorMode.

Two mitigating solutions until this is fixed:

  1. Use useDark and useColorMode once and share the ref across the app to avoid unnecessary calls to the onChange functions. This is not possible whenever a library uses the composable.
  2. Use disableTransition: false to avoid page reflows, but then again, if a library doesn't use the option, we have the same problem.

Potential fixes I can think of:

  1. Do not call the onChange function on usage
  2. Do not call the onChange function if nothing changed
  3. Do not register the same onChange function multiple times

Reproduction

Not required

System Info

All systems

Used Package Manager

npm

Validations

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

1 participant