google / site-kit-wp

Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.
https://sitekit.withgoogle.com
Apache License 2.0
1.25k stars 291 forks source link

Show a loading state for the Navigation Bar. #7916

Closed techanvil closed 11 months ago

techanvil commented 11 months ago

Feature Description

At present, there is a layout shift on the Dashboard due to the Navigation Bar not being rendered at all while its required state is loading.

Loading: image

Loaded: image

We should display the Navigation Bar in a loading state to avoid this layout shift.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation Brief

Test Coverage

QA Brief

Changelog entry

tofumatt commented 11 months ago

Sounds good 👍🏻

We might want to tweak the loading state's width/number of elements/etc. but I think this largely sounds good 🙂

IB ✅

nfmohit commented 11 months ago

Hi @10upsimon!

Ensure that the <LoadingWrapper> component matches the height of the <Navigation /> component to avoid a layout shift.

  • A solution may be to apply the same class as the nav to the <LoadingWrapper> component, i.e className="mdc-chip-set googlesitekit-navigation googlesitekit-navigation--mainDashboard"

Unfortunately, just using the same class doesn't make the preview blocks adapt to the height of the navigation bar. The height of the navigation bar is dynamic based on the height of the chips and their quantity. In the proposed PR, I have set it to two fixed heights for mobile & non-mobile viewports. However, this solution isn't perfect as the layout shift would still occur when the chips wrap into two or more lines (as it isn't possible to determine if they'll wrap at the loading stage).

Any thoughts?

CC: @tofumatt

10upsimon commented 11 months ago

Any thoughts?

@nfmohit I see what you mean, and I agree that it is probably impossible to determine the wrapping final state at the loading state level. In my testing on desktop and mobile, the proposed solution feels more than acceptable, and I do not notice any layout shift, although as you say it may exist in minute proportions.

This LGTM!

wpdarren commented 11 months ago

QA Update: ✅

Verified:

https://github.com/google/site-kit-wp/assets/73545194/5ce1d700-d32c-4867-8bce-af8d41ca71ec