Skip to content

perf: reduce first-load JS bundle size below 200 kB budget #1121

@sw-factory-automations

Description

@sw-factory-automations

Description

All 12 pages exceed the 200 kB first-load JS budget (gzip). The shared base alone is 252 kB across 19 chunks. Week-over-week increases of 17–87 kB on several pages (W19→W20) indicate growing bundle bloat. This affects initial page load time, especially on slower connections.

Source: metrics/weekly/2026-W20-perf.md

Acceptance Criteria

  • Audit shared JS chunks to identify the largest contributors (Lexical, Supabase, Sentry, React, etc.)
  • Apply next/dynamic with ssr: false to heavy client-only components not yet lazy-loaded (e.g., emoji picker, date picker, any remaining Lexical plugins loaded outside the editor page)
  • Verify Sentry SDK is not statically imported in any client component (only via lazyCaptureException or instrumentation-client.ts)
  • Verify lucide-react icons use named imports (tree-shakeable) rather than barrel imports
  • At least 3 pages drop below 200 kB first-load JS (gzip), or the shared base drops below 200 kB
  • pnpm lint && pnpm typecheck && pnpm test pass
  • No visual or functional regressions in E2E tests

Dependencies

None

Technical Notes

  • Current dynamic imports: src/components/page-content-client.tsx, workspace-home-client.tsx, page-icon.tsx, landing-demo-editor.tsx, settings-page-content.tsx, danger-zone-settings.tsx, lazy-route-error.tsx, workspace-settings-form.tsx, page-view-client.tsx, settings-page-client.tsx
  • Sentry already uses lazy capture (src/lib/capture.ts) — verify no other files import @sentry/nextjs directly in client code
  • @lexical/* packages (12 packages) are the heaviest dependency group — ensure they only load on the editor page, not in shared chunks
  • Use npx @next/bundle-analyzer or Turbopack build output to identify chunk composition
  • Reference .agents/conventions.md for dynamic import patterns

Approval Required

This is a HIGH risk change:

  • Modifying import structure across many files risks breaking code-splitting boundaries
  • Dynamic imports change component loading behavior (loading states, hydration timing)
  • Lexical editor chunk restructuring could affect editor initialization
  • Requires careful verification that no functionality regresses

Comment "approved" to release this to the automation queue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-humanNeeds human input — automation will re-queue when user respondsperformancepriority:3

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions