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

I can't get the real breakpoint immediately #1596

Closed
7 tasks done
ByeWord opened this issue May 13, 2022 · 4 comments
Closed
7 tasks done

I can't get the real breakpoint immediately #1596

ByeWord opened this issue May 13, 2022 · 4 comments

Comments

@ByeWord
Copy link

ByeWord commented May 13, 2022

Describe the bug

const breakpoints = useBreakpoints(breakpointsAntDesign)
const resizeHandler = () => {
  console.log(unref(breakpoints.smaller("md")))
  mediaStore.isMobile = unref(breakpoints.smaller("md"))
}
useEventListener(window, 'resize', resizeHandler)
// I have to call nextTick to get real breakopint value
nextTick(() => {
  resizeHandler()
})

Reproduction

none

System Info

System:
    OS: Windows 10 10.0.19043
    CPU: (12) x64 Intel(R) Core(TM) i5-10400 CPU @ 2.90GHz
    Memory: 4.55 GB / 15.86 GB
  Binaries:
    Node: 14.18.2 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - E:\npm\npm_global\yarn.CMD
    npm: 6.14.15 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (101.0.1210.39)
    Internet Explorer: 11.0.19041.1566

Used Package Manager

npm

Validations

@Archetipo95
Copy link

I think that my problem is linked to this issue.
I'm using the code from docs.

const breakpoints = useBreakpoints(breakpointsTailwind)
const lg = breakpoints.isGreater("lg")

And on the template:
<span>{{ lg }}</span>

I'm getting this warning in the console:

runtime-core.esm-bundler.js:38 [Vue warn]: Hydration text content mismatch in <span>:
- Client: false
- Server: true 

@xunmi1
Copy link

xunmi1 commented May 21, 2022

  1. If you use greater, smaller, between, then you don't need to bind the resize event, the return value is a ref.
const breakpoints = useBreakpoints(breakpointsAntDesign);
const isMobile = breakpoints.smaller('md');
watchEffect(() => (mediaStore.isMobile = isMobile.value));
  1. The issue comes from the initial value of useMediaQuery is false, and tryOnBeforeMount can't be safely called in some cases. useMediaQuery is not working as expected #1591 (comment)

@stale
Copy link

stale bot commented Sep 14, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 14, 2022
@stale stale bot closed this as completed Sep 21, 2022
@ideafm
Copy link

ideafm commented Feb 17, 2023

Any result to avoid hydration mismatch?

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

4 participants