Skip to content

perf: the dashboard fetches each page the first time it is opened - #102

Merged
alkhatibdev merged 1 commit into
mainfrom
dashboard-by-page
Nov 17, 2026
Merged

alkhatibdev merged 1 commit into
mainfrom
dashboard-by-page

Conversation

@alkhatibdev

Copy link
Copy Markdown
Owner

The dashboard fetches each page the first time it is opened

The dashboard's script was one file of 847 kB (248 kB gzipped), and every build warned that it was
over Vite's 500 kB. This pull request splits it by page.

What changes

  • Each page is a file of its own, fetched the first time somebody opens it, through React
    Router's lazy.
  • The libraries are two files apart from the dashboard's own code: React and the router in one,
    the rest in the other. Both keep their names through a release that changes only the
    dashboard's code, so a browser keeps them.
  • A first visit fetches 630 kB in five files, 197 kB gzipped, where it fetched 847 kB and 248 kB.
    The build no longer warns.

What splitting brings with it

  • A tab opened before an upgrade asks for the old build's files, which the new image does not
    have. When a page's file cannot be fetched, the dashboard loads the page somebody was opening
    from the server, which brings the new files (lib/upgrade.ts). When it did that less than ten
    seconds before, the file is missing for some other reason, and it does not load again.
  • A page that still cannot be fetched, or fails to draw, says "This didn't load." with Try again,
    inside the frame, so the menu stays. A page that failed to draw used to get React Router's own
    error screen.
  • While the first page's file arrives, the window shows the "Loading" the dashboard already
    shows while it checks the session.

Tests

  • lib/upgrade.test.ts: when the dashboard loads a page again, and where to.
  • router.test.tsx: a page whose file cannot be fetched, inside the frame and outside it. Both
    tests fail without the error boundaries.
  • Three tests now wait for the move to the next page, since a page's first visit waits for its
    file: Shell.test.tsx, Policies.test.tsx and SignIn.test.tsx.
  • Each route's lazy is a function. Written as an object (lazy: { Component }), the tests'
    routers answered "No route matches" on a page's first visit, though the built dashboard did
    not.

Checked

  • The dashboard job's steps in a clean copy, with CI=true and an empty npm cache: the client
    against the contract, lint, types, format, 137 tests, and the build, with no size warning.
    The image build was not run locally; CI runs it.
  • In Chromium and WebKit, the built files served with the dashboard's Content-Security-Policy
    and a stand-in API: a signed-out visit sent to the sign-in page; a page's file fetched only
    when the page opens; an upgrade with a tab open, after which the next page loads from the new
    release; and a release with a page's file missing, which loads once more and then shows the
    error inside the frame. No console errors and no CSP violations in any of them.

Signed-off-by: alkhatibdev <me@alkhatib.dev>
@alkhatibdev
alkhatibdev merged commit 44475c9 into main Nov 17, 2026
4 checks passed
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.

1 participant