SAP / spartacus

Spartacus is a lean, Angular-based JavaScript storefront for SAP Commerce Cloud that communicates exclusively through the Commerce REST API.
Apache License 2.0
741 stars 388 forks source link

Screen size detection at SSR #9086

Open tobi-or-not-tobi opened 4 years ago

tobi-or-not-tobi commented 4 years ago

The screen layout of the Storefront is driven by configurable breakpoints. The breakpoints have a configurable screen size (i.e. < 576px), and associated screen name can be used to further define the layout. A good example is the page template slot configuration, which can be adjusted per screen name, so that the layout differs per screen size (i.e. mobile vs desktop). Other features can however also use the screen names to further enhance rendering of the feature. A good example is the table component, which has a configurable list of headers, based on the screen.

The creation of screen specific DOM is what we call adaptive design. This design is optimised for small screens, but is also optimised for accessibility.

The problem with this technique is that it is driven by the window width. The breakpoint configuration is compared to the actual window width and will change whenever the actual window is changing.

On SSR, we however do not have a window. We cannot find the screen by comparing the window size. This is why we currently use a mobile-first approach on SSR. This is causing issues however, as:

To fix this, we need to take a few pieces into account:

It is not yet clear what level of granularity we'd need to expose for the device. The following comes to mind:

Going forward this list could be extended (i.e. television, game console) or further subtypes could be added (i.e. Pinterest vs Instagram).

tobi-or-not-tobi commented 4 years ago

Given that we're planning this in SSR, we could more easily add a third party lib to do device detection; the CSR bundle size would not be affected by the 3rd party lib.

artem-zur commented 1 month ago

Hello there! Any updates on this issue? We found this behavior very annoying considering that the breakpoint service is often used to implement different mobile adaptations and edge cases.