-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(useSSRWidth): add optional support for SSR in useMediaQuery and useBreakpoints #4317
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
f3c66ad
to
3783e94
Compare
Oh, that's brilliant! I was about to say that it's not possible to know the size of the client on the server side, but yeah, this feature at least provides a solution to that! |
8c10887
to
fa083a3
Compare
}, | ||
{ immediate, flush: 'post' }, | ||
) | ||
() => [targets.value, unrefElement(root as MaybeComputedElementRef), isActive.value] as const, |
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.
Seems like there is a few lint issues that need fixing in the base, though unsure why it only started to popup now
There is a way using HTTP Client Hints via Critical Client Hints, but only on chromium based browsers: |
@userquin Yep, though it's a bit of an unreliable API in that it will only apply to future requests (unless using Critical-CH which will reload the first request), and browser support is only chromium (https://caniuse.com/mdn-http_headers_accept-ch_dpr), and also the client headers are somehow marked deprecated https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Width (seems it's in the process of being replaced with sec-ch-viewport-width) but you should be able to set the header on the nuxt server for all request and retrieve the client width using The headers from this HTTP API can be seen on https://browserleaks.com/client-hints Maybe we should provide a small composable for the nuxt package only where we use I didn't test this yet, but it would look something like this edbad77 |
Yeah, Critical Client Hints would be an interesting approach for this, but I agree it's more on the framework integration scope. I think we could have this feature first and discuss if we could provide better integration for Nuxt later. |
I'm working on getting a minimal repro example (my setup is fairly complex so trying to carve it out) but just for the time being - I upgraded to 12.1.0 and getting |
Spent too much time trying to repro but what problem hasn't been solved by just deleting |
Any hints on how to properly use this new feature? I tried to use it like this: const breakpoints = useBreakpoints(breakpointsTailwind, { ssrWidth: 768 }) But the problem is that as soon as I set I use Is it supposed to work this way? I'm just trying to understand what exactly does this feature do. The docs are scarce about this. What exactly should happen when A reproduce: https://stackblitz.com/edit/nuxt-starter-bt55593r?file=app.vue |
Yes on mounted the values are corrected and yes if the values don't match you get a jump This seems to be a reactivity issue with the object props as other methods like |
Yes this issue appears because the properties are behind a getter and reevaluated on each pass, but it uses a composable under the hood, and the composable is not meant to be called/initialized all of the time, it should only happen within the component setup, but right now it's being called every time vue rerenders, if you keep a reference to the shortcut, this does not happen https://stackblitz.com/edit/nuxt-starter-cnydzchs?file=app.vue |
Before submitting the PR, please make sure you do the following
fixes #123
).Description
Fixes #4102
By adding an optional
ssrSize
option touseBreakpoints
anduseMediaQuery
we can mock their behavior until hydration happens to avoid mismatch errorTests which did not exist for them could now be added thanks to this feature
Notable fixes:
current()
method, this is to avoid the case of a user passing unordered breakpoints causingactive
to be wrongcurrent()
method now returns the list of active breakpoint in accordance with thestrategy
option it previously did not respect itactive
which was a function was not typed as one