Skip to content

Paint the new tab instantly from a saved snapshot - #119

Open
Snuux wants to merge 1 commit into
karakanb:masterfrom
Snuux:fast-first-paint
Open

Snuux wants to merge 1 commit into
karakanb:masterfrom
Snuux:fast-first-paint

Conversation

@Snuux

@Snuux Snuux commented Nov 18, 2026

Copy link
Copy Markdown

What

Opening a new tab now shows the cards almost immediately, with no white flash in dark mode.

Measured on the production build with cached data (median of 10 loads):

Before After
Cards visible ~65–70 ms ~17 ms
App fully mounted ~50 ms ~50 ms

How

  • Snapshot. After each render the page HTML is saved to localStorage (src/snapshot.js, about 80 KB). On the next tab, public/snapshot.js, a small blocking script right after #app, paints it before the bundle loads and refreshes the clock. Vue clears the container on mount and renders the live page in the same task, so the swap is not visible. I compared the snapshot-only page with the mounted page: all elements have the same positions and sizes, and the text is identical. With no snapshot (first run), everything works as before.
  • No white flash. public/theme.js runs first in <head> and sets the page background to the theme color: saved setting, then system preference. App.vue keeps it in step with the day/night toggle.
  • No giant icons. Font Awesome styles are bundled into the CSS (autoAddCss = false) instead of injected by JS. Otherwise the icons in the snapshot rendered unstyled at full size for a frame.
  • content-visibility: auto on card rows, so off-screen rows skip layout.

Both scripts are separate files, not inline, because extension pages (MV3 CSP) do not allow inline scripts.

Notes

  • For about 30 ms after the snapshot appears, buttons (refresh, toggles) are not wired yet. Links work right away.
  • The build and unit tests pass. The existing lint errors in tests/unit/* and vitest.config.js were there before this change.

The new tab used to stay blank until the app bundle loaded and Vue rendered
every card (~65-70 ms with warm data). Now:

- the rendered page is saved to localStorage (src/snapshot.js) and painted by
  a small blocking script (public/snapshot.js) before the bundle loads; Vue
  replaces it on mount in the same task, so the swap is invisible. Cards show
  in ~17 ms. The clock in the snapshot is refreshed to the current time.
- public/theme.js runs first in <head> and sets the page background to the
  theme color, so a dark-mode tab no longer flashes white. App.vue keeps it
  in step with the day/night toggle.
- Font Awesome styles are bundled into the CSS instead of injected by JS, so
  icons in the snapshot never render unstyled at full size.
- rows in cards use content-visibility: auto to skip layout off screen.

Both scripts are files, not inline, because extension pages forbid inline
scripts.

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.

1 participant