Skip to content

Make the first visit paint and fill in sooner (Fix #516) - #518

Open
stephaniehobson wants to merge 12 commits into
mainfrom
516--first-load-performance
Open

stephaniehobson wants to merge 12 commits into
mainfrom
516--first-load-performance

Conversation

@stephaniehobson

@stephaniehobson stephaniehobson commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

One-line summary

Make a first visit paint and fill in sooner on slow connections, and stop the page jumping while it loads.

Significant changes and points to review

  • src/index.jsx requests the current dashboard's index.json at startup, through the new prefetchJSON in withFetch.jsx.
  • New Vite plugin, scripts/indexHtmlPlugin.mjs:
    • writes a static copy of the header and an empty main into #root, generated from config.json, so the header paints before any JavaScript runs;
    • in a build, adds modulepreload links for the route chunks and what they import, plus preload links for their CSS. The chart chunk and the fonts are deliberately left out, because they slowed the main script down on a slow connection;
    • on the dev server, links Application.css and Header.css from the head so the shell isn't unstyled. Hot reload doesn't update those links.
  • If a visitor has tabbed to a static header link before the scripts arrive, src/index.jsx moves focus to the same link in React's header.
  • main stays a window tall while it is empty or shows only the page spinner.
  • Size-adjusted fallback faces in Application.styl: Arial, or Liberation Sans or Arimo, scaled to the Mozilla fonts' widths so text doesn't move when they arrive.
  • A dashboard's "Proceed to" button stays hidden while the dashboard's own spinner shows.

Issue / Bugzilla link

Fix #516

Testing

The timings only show on a production build:

  1. npm run build
  2. npx vite preview --port 4173
  3. In Chrome DevTools, set the network to "Slow 4G" and disable the cache.

Then:

  • Load http://localhost:4173/dashboard/user-activity and check that the header shows while the scripts are still downloading, and nothing on the page moves as the fonts and the dashboard arrive.
  • In the Network panel, check that the route chunks (Home, Contact, DashboardContainer, NotFound, Metric, StripedHeader) start alongside index-*.js, the chart chunk starts later, and user-activity/index.json starts as soon as index-*.js finishes.
  • Check that nothing requests googletagmanager.com.
  • Load http://localhost:4173/ and check the footer doesn't jump down the screen when the page arrives.
  • With JavaScript disabled, check that the header and its links still show.
  • Reload, and press Tab until a header link is focused while the scripts are still downloading. Check it stays focused once the page loads, and that Enter follows it.
  • Run npm start, load http://localhost:3000/, and check the header isn't unstyled before the page appears.
  • Look closely at the fallback fonts in Safari and Firefox. They're tuned from Chromium measurements, and Safari ignores the line-height overrides that would have matched heights too.

Base automatically changed from 468--fresh-paint to main November 19, 2026 20:39
@stephaniehobson stephaniehobson changed the title Make the first visit paint and fill in sooner (#516) Make the first visit paint and fill in sooner (Fix #516) Nov 19, 2026
@stephaniehobson
stephaniehobson force-pushed the 516--first-load-performance branch from 001824f to 222d390 Compare November 19, 2026 20:43

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

Sitewide fallback-font changes need Safari and Firefox validation, while Chromium dev-server coverage leaves production preload timing and font-swap behavior unverified.

No open issues 🎉

What changed in this PR

This PR addresses #516 by improving first-load performance in the Firefox Public Data Report. It shows navigation before JavaScript runs, starts dashboard requests earlier, and reduces layout shifts during loading.

Changes:

  • Add a static header shell, route preloads, and cached dashboard prefetching.
  • Stabilize loading layouts and font swaps, preserve keyboard focus, and skip analytics for the placeholder ID.
  • Add regression coverage and document the implementation, measurements, and follow-ups.
File Description
vite.config.mjs Register the HTML shell and preload plugin.
tests/​playwright/​specs/​jsDisabled.spec.js Check header links without JavaScript.
tests/​playwright/​specs/​fixtures/​shell.spec.js Check shell consistency, styling, layout, and focus handoff.
tests/​playwright/​specs/​fixtures/​next-buttons.spec.js Check that proceed buttons stay hidden during dashboard loading.
tests/​playwright/​specs/​fixtures/​font-fallback.spec.js Measure layout shifts when webfonts arrive.
tests/​playwright/​specs/​fixtures/​early-data.spec.js Check that dashboard data requests precede code arrival.
src/​tests/​jest/​withTracker.test.jsx Cover analytics guards and page-view addresses.
src/​tests/​jest/​withFetch.test.jsx Cover prefetch reuse, shared requests, and failure retries.
src/​tests/​jest/​Routes.test.jsx Update analytics setup and page-view assertions.
src/​tests/​jest/​indexHtmlPlugin.test.jsx Cover shell generation and preload selection.
src/​lib/​withFetch.jsx Expose cached JSON prefetching.
src/​lib/​utils.js Add a shared dashboard index URL helper.
src/​index.jsx Prefetch dashboard data and preserve shell-link focus.
src/​components/​views/​styl/​Spinner.styl Hide proceed buttons while dashboards load.
src/​components/​views/​styl/​includes/​lib.styl Add adjusted fallback fonts to font stacks.
src/​components/​views/​styl/​Application.styl Define fallback faces and reserve loading space.
src/​components/​views/​Header.jsx Add a comment linking header maintenance to the shell copy.
src/​components/​decorators/​withTracker.jsx Guard analytics initialization and attach page-view addresses.
src/​components/​containers/​DashboardContainer.jsx Use the shared dashboard URL helper.
scripts/​indexHtmlPlugin.mjs Generate the shell, production preloads, and development stylesheet links.
docs/​execplans/​2026-11-18-first-load-performance.md Record decisions, performance measurements, and follow-ups.
docs/​architecture/​frontend.md Document startup prefetching and shell behavior.
CONTRIBUTING.md Explain placeholder analytics behavior and test setup.
AGENTS.md Update repository guidance for loading, fonts, and analytics.

Review effort: Balanced

This branch has not been deployed

No deployments
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.

Explore ways to improve first-load performance

2 participants