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

useBreakpoint causes unnecessary rerenders depending on its usage #2177

Closed
7 tasks done
CapitaineToinon opened this issue Sep 6, 2022 · 0 comments · Fixed by #2178
Closed
7 tasks done

useBreakpoint causes unnecessary rerenders depending on its usage #2177

CapitaineToinon opened this issue Sep 6, 2022 · 0 comments · Fixed by #2178

Comments

@CapitaineToinon
Copy link

CapitaineToinon commented Sep 6, 2022

Describe the bug

It seems that two different ways to get the same information through the composable useBreakpoint yield inconsistent renders on the application.

This first example will give me the correct value immediately.

const { isGreater } = useBreakpoints(breakpointsTailwind);

const columns = computed(() => {
  if (isGreater('is2xl')) return 6;
  if (isGreater('lg')) return 4;
  if (isGreater('md')) return 3;
  if (isGreater('sm')) return 2;
  return 1;
});

But this example will have the columns variable to 1 at first, then switch to whatever it actually should be, causing a rerender.

const { sm, md, lg, '2xl': is2xl } = useBreakpoints(breakpointsTailwind);

const columns = computed(() => {
  if (is2xl.value) return 6;
  if (lg.value) return 4;
  if (md.value) return 3;
  if (sm.value) return 2;
  return 1;
});

Could be related to #1596 and #1591? Anyway I think the inconsistent behavior is a problem and should be fixed. Let me know what you think about it.

Regardless, thanks for the awesome library. ✌️

Reproduction

https://play.vueuse.org/#N4IgDghgxg1hDmBTAziAXAbVAOwgW0XRADcBXRAWgBNE8BLEAGhGQHtSAnKQtEU7MDHhMQNZFA50wAFzqtsRAGrkABABFadFQAoAFhAA2AMxV1sKgGIdE2KLoCUp5CogqaxRAdZgz8FaVkDOmkATxcDLwB3ZxD2FWlWFUjJaUQVAFVsOg8OZEMVZTSAGToAIw4ISRQVI1YOAtUAJhUAMhUAZhFOAyJdaWkwZDQAemH+QXgAOihWPGGyShp6YaDS4bMaAA9JvAArVABfRhx8HhAAAQXSZERh5H1rKhE2Tm4icaERMQkpWXkiADKD0QVAa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jjmY7YBOIAnd56V0H5DZBSFkUcOFjcwNFZKxW6CUkxKKWbGlIAZVlFc5TmeUV8+HCFTmxXUiC5WzgmDVyfVNUVQm-UtW171dRHvXDBvM6EcNzD9r843cWD1OzRHX0qMt5BA1xVEbXDO2I8jx1o+-mO3QY93Uo9G4Mdt6fQWt9X6twHRA0JhTMGTtjpG2OkrY6i0+YCzQE4NBN9YZbTfhdQ6qM8EY0OljP+OMpYwOJonCmBlu4ahplQOmDMmbABZtbXm-NwyGAsqbN2ks2E6CVlwgwPCvaa0tjLI2wjRFqzdhbAR2gnbSMQKrM27tPayO9r7Gc-sKFB1gRtUOnVPo4OjsZWOxiE4SjJhTFOCgeoHCAA

System Info

System:
    OS: macOS 12.5.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 792.34 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.7.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 8.15.0 - /usr/local/bin/npm
    Watchman: 2022.08.29.00 - /usr/local/bin/watchman
  Browsers:
    Brave Browser: 90.1.24.82
    Chrome: 104.0.5112.101
    Firefox: 103.0.1
    Firefox Developer Edition: 82.0
    Safari: 15.6.1

Used Package Manager

yarn

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

Successfully merging a pull request may close this issue.

1 participant