From f0577a7a5be2e53dd6f709c12a49608c644c85d7 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Wed, 3 Apr 2024 15:39:54 +0800 Subject: [PATCH] Avoid CLS issue on mobile #10305 On mobile the menu is closed by default. Before, it was opened, then very quickly closed. That leads to a huge Cumulative Layout Shift issue. On http://localhost:4201/, Lighthouse reported a CLS of 0.343, now it is 0. --- projects/natural/src/lib/modules/sidenav/sidenav.service.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/projects/natural/src/lib/modules/sidenav/sidenav.service.ts b/projects/natural/src/lib/modules/sidenav/sidenav.service.ts index 2030053f..c8009aeb 100644 --- a/projects/natural/src/lib/modules/sidenav/sidenav.service.ts +++ b/projects/natural/src/lib/modules/sidenav/sidenav.service.ts @@ -195,7 +195,11 @@ export class NaturalSidenavService extends NaturalAbstractController { assert(this.openedStorageKeyWithName); const value = this.sessionStorage.getItem(this.openedStorageKeyWithName); - return value === null || value === 'true'; + if (value === null) { + return !this.isMobileView(); + } else { + return value === 'true'; + } } /**