Skip to content

perf(widget): lazy-load secondary drawers and preload embed graph - #121

Merged
Ardnived merged 6 commits into
mainfrom
perf/lazy-drawers
Aug 7, 2026
Merged

Ardnived merged 6 commits into
mainfrom
perf/lazy-drawers

Conversation

@Ardnived

@Ardnived Ardnived commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Lazy-loads the three secondary drawers and flattens the embed entry's import graph, cutting the eager first-load payload by roughly 100 KiB gzipped.

DrawerStack statically imported CalendarView, RegistrationView and ShareView, so every visitor downloaded the entire Schedule-X calendar, react-hook-form and react-share before first paint — for panels most never open. The molecules barrel additionally held swiper and react-share eager, defeating the split for consumers that only wanted a neighbouring component.

Measured effect (eager payload, gzipped)

Measured with pnpm size — entry plus the full modulepreload closure for the standalone shell, and embed.js's import graph — never a single chunk, since the build re-chunks freely.

Graph Before After
standalone 481.8 KiB 382.1 KiB
embed 483.3 KiB 383.6 KiB

BUDGET_KIB is ratcheted 495 → 395 in the same change, as scripts/check-bundle-size.mjs requires: it fails when a graph comes in far under budget precisely so a win is banked rather than left as slack.

Also included

  • Strips .DS_Store from the build output.
  • Tightens the embed.js smoke spec around the flattened entry graph.
  • README: code-splitting makes script-src load-bearing in a way it wasn't before. A host policy that allows the <script> tag but not the subresource fetches now yields a widget that looks fine and then fails on one of three presses.

Review coverage — please read

The platform had a sustained API-instability window during this work. The security review completed; both attempts at /code-review died mid-run, so its findings were triaged inline rather than by a fresh reviewer. A human pass over the lazy-loading seams is worth it.

The drawer chrome must render immediately while a lazily-loaded body chunk resolves — the failed-chunk retry pattern from EventView is replicated — but that is a behaviour the unit lane cannot express. Manual check worth doing: open the calendar, registration and share drawers on a cold load and confirm no blank or unstyled flash, and that a throttled/failed chunk surfaces the retry rather than an empty panel.

Note for merge ordering

#119 (swiper v12) independently reduces the eager payload and is not in this branch, so BUDGET_KIB may want one further adjustment once both land.

Closes #96

Ardnived and others added 6 commits August 6, 2026 21:37
The three drawers most visitors never open were statically imported by
DrawerStack, so every host page paid for the whole Schedule-X stack,
react-hook-form and react-share before first paint.

Each `lazy` is minted per attempt rather than once at module scope, for the
reason EventView already documents: React caches a rejected payload forever,
so a module-scope lazy would leave the drawer boundary's "Try again" dead.

The existing Suspense sits outside the boundary, so a chunk load shows
DrawerLoading — the shared chrome rebuilt from the URL over a spinner — and
only a failure throws inward. The drawer keeps its header and close control
from the first frame.

Closes #96

Co-Authored-By: Claude Fable 5 <[email protected]>
…share eager

Lazy-loading the three drawers moved far less than expected, because the
heavy components were still reachable from the eager graph through the
molecules barrel — which eager views import. Tree-shaking will not drop them:
their swiper/react-share imports carry side effects.

ImageCarousel, EventActions and ShareContent each have exactly one real
consumer, and all of those already sit inside lazily-loaded chunks and reach
them by leaf path. Nothing imported them through the barrel, so removing the
re-exports is the barrel rule this file follows everywhere else.

Worth 44.7 KiB gz of the total, and pinned by a spec, because the size gate
catches the bytes but names a budget rather than the line that caused it.

Closes #96

Co-Authored-By: Claude Fable 5 <[email protected]>
Vite writes a modulepreload for the entry's whole static closure into
index.html, so the standalone page discovers every eager chunk from one
parse. embed.js has no shell, and imported only 7 of its 10 chunks directly
— the three it missed included `shared`, the largest in the payload. A third
of the embed's bytes arrived one round trip late.

An injected <link> cannot fix that even in principle: a module's static
imports are fetched and evaluated before its body runs, so a hint written
from inside embed.js is always later than the graph it would hint at.
Appending the missing chunks to the entry's own import list is the same
information somewhere a host reads it in time — and appended last, so
evaluation order is untouched and they only add fetch parallelism.

Also sweeps .DS_Store from the output: publicDir is copied wholesale and has
no ignore option, and the file is gitignored, so nobody sees it in review.

Closes #96

Co-Authored-By: Claude Fable 5 <[email protected]>
495 -> 395 KiB on both graphs, against 382.1 (standalone) and 383.6 (embed).
Same ~3% headroom the previous line carried. The under-budget guard fails
until this lands, which is what stops the slack being re-accumulated.

Closes #96

Co-Authored-By: Claude Fable 5 <[email protected]>
- Extract flattenEntryImports to scripts/, matching the postcss-scope-widget
  precedent, and unit-test the graph walk and specifier math. That logic could
  regress silently: flattening changes discovery, not bytes, so `pnpm size`
  cannot see it.
- The missing-entry guard now errors instead of warning. A warning is as
  invisible as silence — nothing overrides onwarn and Vite does not fail on
  rollup warnings — so renaming the input key would have reverted the
  optimization with every gate green.
- Document why only a NON-HASHED entry may be flattened: generateBundle runs
  after hashing, so rewriting a hashed entry ships bytes that no longer match
  the hash in their own filename.
- stripDsStore: one recursive readdir instead of hand-rolled recursion (the
  spelling assert-css-scoped already uses), resolve outDir against config.root
  rather than cwd, and skip a write:false build instead of rejecting.
- Fold three overlapping barrel comments into one; drop a comment orphaned by
  the export it described.

Co-Authored-By: Claude Fable 5 <[email protected]>
Lazy-loading the calendar, registration and share panels changes what a
host's CSP has to allow: the <script> tag now fetches a small entry which
pulls the rest as further script requests from the same origin, and those
three panels are fetched only on first open. A policy that allows the tag
but not the subresource fetches yields a widget that looks fine and then
dies on one of three presses — miserable to diagnose, so the README now
says it outright.

Also flattens the embed entry's import graph and tightens the embed smoke
spec around it.

Closes #96

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sahajatlas-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: 671680c
Status: ✅  Deploy successful!
Preview URL: https://9d1e1bbc.sahajatlas-design.pages.dev
Branch Preview URL: https://perf-lazy-drawers.sahajatlas-design.pages.dev

View logs

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: 671680c
Status: ✅  Deploy successful!
Preview URL: https://173cfd6b.sahajatlas.pages.dev
Branch Preview URL: https://perf-lazy-drawers.sahajatlas.pages.dev

View logs

@Ardnived
Ardnived merged commit 2eb7a63 into main Aug 7, 2026
5 checks passed
@Ardnived
Ardnived deleted the perf/lazy-drawers branch August 7, 2026 16:19
Ardnived added a commit that referenced this pull request Aug 7, 2026
One conflict, in README.md's CSP block, and it was load-bearing: this
branch added `https://cdn.usefathom.com` to script-src plus a warning
that CSP ignores every repeat of a directive name after the first, while
#121 added the widget's own origin as a SECOND `script-src` line — the
exact mistake the warning describes. Merged onto one line carrying all
three sources, so a host pasting the block actually gets Turnstile and
Fathom rather than silently losing them, and kept both explanations.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.

perf(widget): lazy-load secondary drawers and preload embed graph

1 participant