Skip to content

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

Closed

Description

@Ardnived

Summary

The release-readiness review (.claude/reports/RELEASE_READINESS.md §1.1, Appendix A — local, gitignored) measured the eager payload at 477 KiB gzipped for the standalone page (entry + every modulepreload in dist/index.html) and ~490 KiB for the embed graph — roughly 3–5× a reasonable budget for a third-party embed. A further ~400 KiB gz mapbox-gl chunk is discovered only after the App chunk parses, so the real payload before first meaningful paint is ≈877 KiB gz as a serial waterfall. The main drivers are three secondary drawer views that most visitors never open, all statically imported by DrawerStack — the calendar (the entire Schedule-X stack: ~720 sx__ selectors land in the eager App chunk), registration (react-hook-form), and share (react-share). This ticket adds lazy seams for those three views, gives the embed entry the preload hints it currently lacks entirely, and cleans up two build-output warts found alongside.

Current behavior

  • src/views/DrawerStack/DrawerStack.tsx:34,39,40 statically import CalendarView, RegistrationView, and ShareView (report snapshot cited lines 27,32,33; verified at these lines on feat/classify-errors). All three ride in the eager graph.
  • Only 3 lazy seams exist today: EventDetails (via EventView), the Lightbox, and the admin PreviewController.
  • EventView already carries the right retry pattern for a lazy seam: loadEventDetails (src/views/EventView/EventView.tsx:25-41) mints a fresh lazy() per attempt, because React caches a lazy component's rejected payload forever — a module-scope lazy would make the boundary's "Try again" a visibly-does-nothing button (issue feat(widget): classify errors and show only the actions that can help #89). Replicate this, don't reinvent it.
  • Swiper is bundled twice (both the App and EventRegister eager chunks) even though its only consumer sits behind the lazy EventDetails chunk (report §1.1 / Appendix A).
  • dist/embed.js emits zero modulepreload hints (grep-confirmed against a production build) — host embeds get a strictly deeper discovery waterfall than the standalone page, which at least gets <link rel="modulepreload"> tags in dist/index.html.
  • .DS_Store files are deployed in dist/ (report §1.1 housekeeping).

Proposed changes

  • React.lazy the three drawer views (CalendarView, RegistrationView, ShareView) from DrawerStack, each behind a Suspense fallback consistent with the existing drawer loading chrome (DrawerLoading / the existing boundary + suspense structure in DrawerStack), and using the minted-per-attempt lazy retry pattern from EventView.tsx:25-41 so a failed chunk load stays recoverable.
  • Respect the boundary/seam rules in .claude/rules/i18n-and-state.md (error-boundaries section): the drawer chrome must render immediately while the body chunk loads — never split a view to manufacture a seam; the fallbacks render their own chrome.
  • After the seams land, verify the Swiper duplication disappears from the eager graph (it should follow EventDetails's chunk); if it doesn't, chase and document the cause.
  • Emit modulepreload hints for the embed entry's eager graph — either a Vite plugin that injects link preloads from embed.js at runtime, or a documented host snippet; implementer evaluates and records the decision.
  • Exclude .DS_Store from build output.

Acceptance criteria

  • CalendarView, RegistrationView, and ShareView load via lazy seams; @schedule-x/*, react-hook-form, and react-share no longer appear in the eager graph (e.g. no sx__ selectors in the eager App chunk).
  • Before/after eager-payload numbers in the implementation report, measured the honest way (per project memory: never claim a bundle saving from one chunk's size — rolldown re-chunks): entry + every modulepreload in dist/index.html, gzipped, both before and after — and the equivalent full eager graph for embed.js. Expected ballpark: 150–250 KiB gz reduction.
  • No drawer flashes unstyled or blank on first open: the drawer chrome (header, close control) renders immediately while the body chunk loads, per the seam rules in .claude/rules/i18n-and-state.md.
  • A failed chunk load is retryable: the boundary reset mints a fresh lazy per the EventView.tsx:25-41 pattern (no permanently-cached rejection).
  • Swiper appears in at most one chunk, reachable only behind the lazy EventDetails graph — or the cause of the duplication is chased and documented.
  • dist/embed.js consumers get preload coverage for its eager graph (plugin), or the documented host-snippet alternative is written up with the decision rationale.
  • No .DS_Store files in dist/ after a clean build.
  • pnpm lint && pnpm typecheck && pnpm test:run && pnpm build pass.
  • Write an implementation report to .claude/reports/<issue-number>-lazy-drawers.md — in the MAIN checkout at /Users/devindra/Documents/Projects/SahajAtlasWeb even when implementing from a worktree (the folder is gitignored) — covering what changed, what was deliberately NOT changed, and which readiness-report findings are resolved.

Files affected

  • src/views/DrawerStack/DrawerStack.tsx — imports/lazy seams only
  • vite.config.ts — plugins section only
  • src/views/CalendarView/CalendarView.tsx, src/views/RegistrationView/RegistrationView.tsx, src/views/ShareView/ShareView.tsx — export shape only, if the lazy wrapper needs it

Parallel implementation: this ticket OWNS the files above; sibling release-hardening tickets run concurrently. In shared files the ownership is regional: a sibling a11y ticket owns the PeekStrip component region of DrawerStack.tsx (this ticket touches only the import/lazy-seam region), and a sibling ticket owns the build-output section of vite.config.ts (this ticket touches only the plugins section). Avoid edits outside owned files/regions except strictly additive ones.

References

  • .claude/reports/RELEASE_READINESS.md §1.1, §1.6 (recommendations 1–2, 6), Appendix A (local, gitignored)
  • Retry-on-failed-chunk pattern: src/views/EventView/EventView.tsx:25-41 (issue feat(widget): classify errors and show only the actions that can help #89)
  • Boundary/seam rules: .claude/rules/i18n-and-state.md (error-boundaries section)
  • Bundle-measurement rule (project memory): measure the eager payload — entry + every modulepreload in dist/index.html, gzipped — both ways; React.lazy on a component that renders at mount defers nothing

Activity

  1. added a commit that references this issue on Aug 7, 2026
    671680c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Hold Until

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions