Skip to content

perf(site): stop whole-page restyles on the home page, set sections up as they near the view - #105

Merged
b4rb13 merged 2 commits into
mainfrom
site/home-perf
Nov 20, 2026
Merged

b4rb13 merged 2 commits into
mainfrom
site/home-perf

Conversation

@b4rb13

@b4rb13 b4rb13 commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Summary

Profiling showed that the long tasks on / were mostly style recalculation, not JavaScript. One CSS rule made every DOM change restyle the whole page.

 apps/site/src/styles/home.css
-:root:has([data-va-hero]) .site-footer { margin-top: 0 }

 apps/site/src/components/site/Footer.astro
+const home = Astro.url.pathname === '/';      // same check as Hero.astro
+<footer class:list={['site-footer', 'not-content', { home }]}>
+.site-footer.home { margin-top: 0 }

Why it was so expensive: :root:has(…) .site-footer makes <html> a non-subject :has() anchor. On every node inserted or removed anywhere, Chromium schedules its merged :has() invalidation set on that anchor. Starlight's list-spacing rule (.sl-markdown-content :is(ol,ul):has(> li > …) > li > …) makes that set "all descendants". So each loader update restyled 2,000–3,800 elements, and every getBoundingClientRect / getComputedStyle the runtime makes paid for it. Removing either rule fixes it. Starlight's rule is left alone; ours goes.

Then, as the brief asked, the sections stop setting up all at once:

 startHero()                        // first screen: immediate, as before
-  registerAll()
+  register block, text, chart, table, region   // its own five only
 Inbox, Invoices, Activity, Family, Handoff, Playground, Details, GetStarted, Closing
-  registerAll(); set up            // all at load
+  whenNear(section, () => {        // within a window's height, own task
+    register what this section uses; set up
+  })

Layout reads are batched too:

  • shapeRows (lib.ts): measures every cell before it writes. Used by the hero and invoices tables.
  • Activity feed glide: reads every position, then does one reflow instead of one per item.

Evidence

Main-thread time: / at 412 × 823, 4× CPU, 150 ms RTT at 1.6 Mbps, local build. Median of 7 runs. TBT here is the sum of (long task − 50 ms) from FCP to 10 s, which includes the first screen's loop.

Before CSS fix only (5 runs) After
TBT, FCP to 10 s 857 ms 233 ms 110 ms
TBT, FCP to 5 s 607 ms 225 ms 110 ms
Blocking while scrolling to the end 253 ms (14 long tasks) — 0 ms (none)
FCP / LCP / CLS 1640 / 1724 ms / 0.01 same 1640 / 1720 ms / 0.01

The same profiler measures production (https://dotquilt.dev/, 3 runs) at 1,213 ms, in line with the audit's 1,280 ms. Production is higher than the local build because of real serving; the before/after ratio is the comparison that matters.

Where the time went before:

  • 2.5 s: a 351 ms task, registration and upgrades. 217 ms of it was style recalculation, forced by eligible() → getBoundingClientRect.
  • 4–6 s and 9–11 s: 90–200 ms tasks on every loop of the first screen, from text loader measurements and handoffs. About 75% of each was restyling ~2,200–3,800 elements.

Tests: three new ones in tests/site/home.spec.ts.

a change inside one section restyles that section, not the whole page
  append a <div> to the inbox thread, force style, read the Chromium trace
  before: ✘ 2,670 elements restyled (the page has 1,353)
  after:  ✓ under a tenth of the page

sections further down set up as they near the view, not at load
  before: ✘ the steps' skeleton lines are already upgraded at load
  after:  ✓ not upgraded at load; brought into view → upgraded, handoff "complete"

the closing field meets the footer on the home page only
  ✓ before and after: margin-top 0px on /, 64px on /docs/
  • Site suite: bunx playwright test --project=site-chromium → 85 passed, including the first screen, hold-to-load, invoices, activity, family, handoff, playground and details tests.
  • Other checks: bun run lint, bun run check, bun run test pass.

Same look, same behaviour. These checks compared the before and after builds and were not committed:

  • Pixel diff: full-page screenshots with reduced motion, taken after scrolling through. 0 differing pixels at 412 px and at 1440 px, footer included.
  • Arrivals with motion: scrolled like a reader, stopping at each section. Every section's handoffs ended the same way in both builds, at 1280 and 412 px. For example: inbox, invoices and activity complete; family 5 complete + 1 immediate; closing 2 complete.

Merge Danger

Door: two-way

A revert restores the old scripts and rule. Nothing is stored or published.

Blast Radius: home page

  • Section setup now happens later. It runs when a section is within one window height of the view, not at load. A reader who jumps straight into a section, by dragging the scrollbar for example, can reach it before it has set up:
    • Inbox, invoices and activity then show their content finished, without the entrance load. The existing rule still applies: a section already on screen isn't hidden.
    • The other sections upgrade from their server-rendered placeholders while in view, then load as before.
  • The footer change applies to every page. Only / gets the home class, and the test checks both cases.
  • Overlap with SEO fixes and a social card for every page #103: it touches Footer.astro and tests/site/home.spec.ts, but in different places, so it should rebase cleanly.

🤖 Generated with Claude Code

b4rb13 and others added 2 commits November 21, 2026 02:19
`:root:has([data-va-hero]) .site-footer` made the root element a `:has()`
anchor. Chromium then scheduled its merged `:has()` invalidation set on
<html> for every node inserted or removed anywhere on the page, and
Starlight's list-spacing rule makes that set "all descendants". Each
loader update therefore restyled 2,000 to 3,800 elements, and every
forced style read paid for it.

The footer now knows it is on the home page (the same check Hero.astro
uses) and drops its top margin there, so the page looks the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every home section registered all nine elements and wired up its demo
at load, so the whole page upgraded in the first seconds. Now:

- the first screen registers only its own five elements and starts at
  once, as before;
- each section further down registers what it uses and sets up once it
  is within a window's height of the view, in a task of its own;
- shapeRows measures every cell before its first write, and the
  activity feed reads every position before it restarts the glides with
  a single reflow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
dotquilt Ready Ready Preview Nov 20, 2026 10:20pm UTC

Request Review

@b4rb13
b4rb13 merged commit fec9814 into main Nov 20, 2026
7 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