Skip to content

Stop the page moving while charts load, and keep pages steady when moving between them (fix #509) - #511

Merged
stephaniehobson merged 7 commits into
mainfrom
509--reserve-chart-space
Nov 18, 2026
Merged

stephaniehobson merged 7 commits into
mainfrom
509--reserve-chart-space

Conversation

@stephaniehobson

Copy link
Copy Markdown
Collaborator

Fixes #509.

Each metric used to render nothing while its data loaded, so every chart that arrived pushed the rest of the page down. Fixing that showed the same problem when moving between pages, so this also covers the rest of the browsing experience. Each commit stands alone and passes lint and tests.

  1. Reserve space while loading. A pending metric or summary bar renders a placeholder the size of what replaces it. The spinner shown while the chart code loads takes the chart's size. Only descriptions and legends, whose height isn't known until the data arrives, still move what's below them.
  2. Footer at the bottom of the window. Short pages such as Contact and Not Found put the footer at the bottom of the window. While a dashboard loads, the footer stays out of sight, so it no longer jumps off the screen when the dashboard arrives. That jump was the largest shift left.
  3. No reloading on a return visit.
    • Lazy components are created once, and loaded code renders straight away.
    • withFetch keeps responses until the page reloads, and components asking for the same URL share one request.
    • A page you've visited appears at once.
    • A chunk that fails to load now offers a page reload. Browsers can cache a failed import(), so the old retry on the next visit wasn't reliable.
  4. New pages open at the top. Firefox and Safari opened a revisited page part way down after the Next button.
  5. Focus after navigating.
    • Focus moves to the new page's heading, as a full page load would. A screen reader reads it, and Tab continues from there.
    • Back and Forward keep their scroll position.
    • The route and dashboard spinners tell screen readers they're loading.
    • Not Found has its own title.

Layout shift on first load, measured with data delayed 200–800ms:

Dashboard Before After
hardware @1280px 0.52 0.006
user-activity @1280px 0.82 0.06
usage-behavior @1280px 0.72 0.06
hardware @375px 0.40 0.013

Testing:

  • New Playwright specs:
    • fixtures/placeholders.spec.js: each placeholder takes the space of what replaces it, and the footer stays out of sight while a dashboard loads.
    • fixtures/navigation.spec.js: revisits show no loading states and make no data requests, the Next button opens pages at the top, and focus lands on the right element after each kind of navigation.
  • footer.spec.js now checks that short pages put the footer at the bottom of the window.
  • New unit tests cover the response cache (shared, abandoned, failed and out-of-order requests), lazyLoad, the spinner's status text, page views across navigation, and the Not Found title.
  • Lint, Vitest (134 tests) and the recorded Playwright run (110 tests) pass. I haven't run the live-data job.
  • Checked with a keyboard in Chrome, Firefox and Safari: after the Next button, the heading has focus at the top of the page, Tab goes to the region selector, and Back keeps the scroll position.
  • Not yet checked with a screen reader. With VoiceOver and Safari, check that each dashboard's title is read after navigating, that "Loading dashboard" is read on a slow first visit, and that the previous page's title is read after Back.

Each metric rendered nothing until its data arrived, then a spinner the
height of a few dots until its chart code arrived, so every chart that
loaded pushed the rest of the page down. Summary bars also rendered
nothing while loading, and collapsed again on every region change.

Pending metrics and summary bars now render a placeholder the size of
what replaces them, and the spinner while the chart code loads takes
the chart's size. Only descriptions and legends, whose height isn't
known until the data arrives, still move what's below them.
On short pages like Contact and Not Found, the footer sat just below the
content, part way up the window. The page is now a column at least as
tall as the window, with main taking the spare height.

While a dashboard loads, main is also at least as tall as the window,
so the footer stays out of sight instead of jumping off the screen when
the dashboard arrives. That jump was the largest layout shift left on
every dashboard.

The gap above the header moves from a relative offset to padding, so
that it counts toward the page's height instead of making every page
scroll by it.
Moving between pages flickered through spinners and placeholders even
on a return visit. Main and MetricOverview created a new React.lazy on
every mount, which suspends once even when its code has loaded, and
withFetch fetched every response again, with the CDN forcing max-age=0.

lazyLoad now renders loaded code straight away, and the lazy components
are created once. withFetch keeps responses until the page reloads and
shares one request between components asking for the same URL, which
hardware's summary bars and metrics do.

A chunk that fails to load is no longer loaded again on the next visit.
Browsers can keep a failed import() too, so that retry wasn't reliable;
the error now offers a page reload instead.
BrowserRouter leaves the window scrolled where it was. Now that a page
visited before renders at full height at once, the Next button opened
it part way down in Firefox and Safari. Back and forward still keep the
browser's own scroll restoration.
After a client-side navigation, focus stayed on the header link, or
fell to the body when the Next button that had it was replaced, and
screen readers weren't told that a new page had loaded. Focus now moves
to the page's heading, as a full page load would start at the top, so a
screen reader reads it and Tab continues from there. Back and forward
keep their scroll position. Until a dashboard's heading arrives, main
holds focus, and the heading takes it unless the reader has moved on.

The route and dashboard spinners now tell screen readers they're
loading, once the dots appear, and Not Found has its own title instead
of the previous page's.

This comment was marked as resolved.

An unknown URL under /dashboard/ took the dashboards' full-height
layout, pushing its Not Found page's footer below the window. The
layout now applies only to configured dashboards, matched as the
routes match them.

The chart and table code started loading on every page, because
MetricOverview comes with the dashboard page's code, which every page
starts loading. lazyLoad can now defer loading until first render, and
MetricOverview's components do.

When a page's code failed to load after navigating, focus stayed on
main and the error wasn't announced. The route-level error heading now
takes focus as a page heading does.

Moving from a request in flight or failed to a URL whose cached
response was empty left the component pending or rejected, as both
have no value. It now updates whenever it isn't already fulfilled.
Deferring the chart and table code until a metric renders saved a
download only for visitors who never open a dashboard, which is few,
and brought back the wait on a first dashboard visit: the chart code
started loading only once the metric's data had arrived. Starting it
with the dashboard page's code, which every page loads, means it is
usually ready before the data is.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Route-wide focus management and live-region announcements require outstanding human VoiceOver/Safari validation, including heading and loading announcements during Back navigation.

1 open issue
3 resolved since last review

Review effort: Balanced

@stevejalim stevejalim left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

robotstamp+

@stephaniehobson
stephaniehobson merged commit 4d60910 into main Nov 18, 2026
7 checks passed
@stephaniehobson
stephaniehobson deleted the 509--reserve-chart-space branch November 18, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Layout shifts as graphs load

3 participants