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

$q.screen.width and $q.screen.height is always 0 in SSR mode #8924

Closed
3 of 14 tasks
SuspiciousLookingOwl opened this issue Apr 16, 2021 · 3 comments
Closed
3 of 14 tasks
Assignees
Labels

Comments

@SuspiciousLookingOwl
Copy link

SuspiciousLookingOwl commented Apr 16, 2021

Describe the bug
$q.screen.width always returns 0 on quasar dev -m ssr and running the build app from quasar build -m ssr. This also broke $q.screen.gt (always return false) and $q.screen.lt (always return true). $q.screen.width on SPA mode (quasar dev) returns the correct value.

Codepen/jsFiddle/Codesandbox (required)
https://codesandbox.io/s/quiet-smoke-vn1k1

  • Create Terminal
  • npm run start:ssr (npm run start for SPA mode to ensure that it works properly)

To Reproduce
Steps to reproduce the behavior:

  1. Create Quasar v2 project (quasar create app-name --branch next)
  2. Run quasar dev server on ssr mode (quasar dev -m ssr)
  3. Add {{ $q.screen.width }} to the component
  4. It will shows 0

Expected behavior
$q.screen.width should return the width size

Platform (please complete the following information):
Quasar Version: ^2.0.0-beta.1
@quasar/app Version: ^3.0.0-beta.1
Quasar mode:

  • SPA
  • SSR
  • PWA
  • Electron
  • Cordova
  • Capacitor
  • BEX

Tested on:

  • SPA
  • SSR
  • PWA
  • Electron
  • Cordova
  • Capacitor
  • BEX

OS: Windows 10
Node: 14.15.3
NPM: 6.14.9
Yarn: -
Browsers: Microsoft Edge 89.0.774.76, Firefox 86.0.1
iOS: -
Android: -
Electron: -

Additional context

  • Works fine on SPA mode
  • Works fine on quasar version ^1.0.0 and @quasar/app version ^2.0.0 (from quasar create app-name)
@SuspiciousLookingOwl SuspiciousLookingOwl changed the title $q.screen.width is always 0 in SSR mode $q.screen.width and $q.screen.height is always 0 in SSR mode Apr 16, 2021
@TobyMosque
Copy link
Contributor

TobyMosque commented Apr 16, 2021

there is little to nothing what we can do here. but I'll try to show some alternatives.

1 - don't use the Screen Plugin and use a CSS based solution (media queries)
2 - use client hints as a fallback on the server side, but remember, that had some caveats, so isn't bulletproof:

  • It will not work in the first call
  • will not handle the height
  • requires SSL (u'll need a valid HTTPS certificate)
  • the browser will cache that value, so if u resize the page than refresh, u'll get a old value (probably).

https://developer.mozilla.org/en-US/docs/Glossary/Client_hints

@rstoenescu rstoenescu self-assigned this Apr 16, 2021
@rstoenescu
Copy link
Member

Identified the problem. Post hydration logic is not called. Will fix it next week.

@rstoenescu
Copy link
Member

Fix will be available next week in Quasar v2.0.0-beta.13 AND "@quasar/app" v3.0.0-beta.16 (needs both).
It will also contain the promised Webpack 5 upgrade.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants