Closed zweeen closed 9 months ago
Hi, @zweeen!
It doesn't work inside stackblitz, because cookie SameSite=Strict
, I can remove that. For now try to test here
I split the plugin into client and server, tested in different versions of Nuxt and everything worked. That's the only thing that could have broken.
Have you tried to use the previous version inside your project, did it solved the issue?
https://github.com/mvrlin/nuxt-viewport/assets/24970784/d189945e-61a8-4622-93e1-1f82c2309815
Hi @mvrlin,
Sorry for my late response.
It's working as you said. When cookie same-site
is set to strict
it doesn't work when we load the page for the very first time.
Can you remove it, or may be it's better to pass it as config option (and all other cookie options btw) like the cookieName.
Thanks in advance π
Hey, @zweeen. Please, check out the latest release https://www.npmjs.com/package/nuxt-viewport#default-configuration
Thanks a lot @mvrlin for your super reactivity π .
The release is just perfect ππΌ.
I close the issue.
@mvrlin on SSR rendered app when you enter first time and the viewport
cookie is not setted the fallbackBreakpoint value is set.
Also when you have a tab opened on mobile view, and you close it and open a new tab the viewport cookie is the first tab value.
Is there a solution, or workaround for this ?
@norbertSG Can you give more information about the first request? What do you expect? You want Set-Cookie
header?
About tabs sync I can investigate this https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel
When you enter first time on the app i would like to get from the server the correct viewport, as the nuxt/device plugin works, right now on the server is undefined and on the client will be set to the correct value.
Tabs switching issue, i would like when i open a new tab on the same browser, to update the viewport value in the cookie, and do not take it from the cookie if is set, the cookie could be uniq per tab. Because if i have the app opened and i open the devtools then the viewport size will be xs(mobile) if i close the tab and open a new one it will take the value from the cookie and set it to xs(mobile) not the actual viewport of desktop.
@norbertSG
undefined
, it tries to guess based on User-Agent
. This is how it works on the server:
On client side, it will read the cookie value as the base value, then when `suspensed` hook is triggered will compute the browser width and set the correct value and update the cookie.
Are you asking for Set-Cookie
on the first request?
@mvrlin
@norbertSG I don't see the point of checking if the cookie is the same as the server guessed. Because I can have mobileMedium
in the cookie, but the server will detect only mobile
based on the User Agent without knowing the screen size.
@mvrlin
Logs from the server:
Cookie:
viewport desktopWide
curren bp [] 640
User-Agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1
User-Agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1
Cookie:
viewport desktopWide
I am talking about this scenario, because initial i had in the cookie desktopWide will return desktopWide from the server, and the update to mobile will be done on the client, but here we could check if the cookies value is different from the user agent then return the user agent derived value into the cookie
@norbertSG I understand you, but what about my example when you have mobileMedium
in cookie and server detects from User-Agent as mobile
?
@mvrlin in my point off view you can keep the one from the cookie, its much more appropriate, just then overwrite the cookie value when is different device(mobile,tablet, desktop)
@norbertSG that's quite difficult to do due to breakpoints naming, I don't have control about how breakpoints will be named.
Hi @mvrlin , thank you for this awesome module you rock π.
I use the latest nuxt version 3.9.1 and nuxt-viewport 2.1.0, but it seems that this module doesn't work on SSR. I tried it 2 month ago (I think) and it's worked perfectly client side and server side.
When I refresh the page I can see the value returned by the composable updating.
What is expected: when refreshing the page the value must stay the same.
Here an example of the bug:
https://stackblitz.com/edit/github-xt2p8e?file=app.vue,nuxt.config.ts