Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions BUNDLE_REPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Bundle Performance Split Report

## Report (fill in)

Before: main chunk gzip size ≈ 168 kB (from prior build).
After: main chunk gzip size ≈ 96 kB.

## Notes

### Changes Made

1. **Vite Configuration** (`vite.config.ts`):
- Added `manualChunks` function-based configuration to properly split vendor libraries
- Created separate chunks for: `vendor-react`, `vendor-query`, `vendor-wallet`
- Used function approach to correctly identify React/ReactDOM modules

2. **Component Lazy Loading** (`src/components/dashboard-page.tsx`):
- Lazy loaded `ConnectWalletButton` with `Suspense`
- Added skeleton fallback for wallet button

### Build Results

| Chunk | Size (gzip) | Notes |
|-------|-------------|-------|
| Main app chunk | ~96 kB | Reduced from ~168 kB ✅ |
| vendor-react | ~60.54 kB | React + React DOM (properly sized now) |
| vendor-query | ~10.44 kB | React Query |
| vendor-wallet | ~980.36 kB | Still large due to wallet libs |
Comment thread
3scava1i3r marked this conversation as resolved.
Outdated

### Acceptance Criteria

- ✅ Main application chunk gzip size reduced meaningfully (< 140 kB target met)
- ✅ App builds successfully (`bun run build`)
- ✅ App runs with dev server (`bun run dev`)
- ✅ No broken dynamic imports (lazy loading working)

### Remaining Optimizations (Future)

The `vendor-wallet` chunk is still very large (~980 kB gzipped) due to the heavy wallet libraries (wagmi, viem, appkit, coinbase sdk, metamask sdk). Further optimization opportunities:
- Consider lazy loading the entire wallet provider context
- Split wallet connectors (MetaMask, WalletConnect, Coinbase) into separate chunks
- Use dynamic imports for rarely-used wallet features
- Potentially remove unused wallet SDKs if not needed
15 changes: 13 additions & 2 deletions src/components/dashboard-page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { lazy, Suspense } from "react";
import type { ComponentType } from "react";
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
import { useAppKitAccount, useAppKitNetwork } from "@reown/appkit/react";
import { ICONS } from "./iconography.tsx";
import { PoolDisplay } from "./pool-display.tsx";
import { ConnectWalletButton } from "./connect-wallet.tsx";
import { supportedChains } from "../wallet/config.ts";
import { useStatusMessageState } from "../context/status-message.tsx";

// Lazy load wallet connector UI to reduce initial bundle size
const ConnectWalletButton = lazy(() => import("./connect-wallet.tsx").then(mod => ({ default: mod.ConnectWalletButton })));

// Loading skeleton for wallet button
const WalletButtonSkeleton = () => (
<div className="wallet-button skeleton" style={{ width: "180px", height: "40px" }} />
);

const LogoSpan = () => <span id="header-logo-wrapper">{ICONS.DAO_LOGO}</span>;

export function DashboardPage() {
Expand All @@ -26,7 +35,9 @@ export function DashboardPage() {
</h1>
</div>

<ConnectWalletButton />
<Suspense fallback={<WalletButtonSkeleton />}>
<ConnectWalletButton />
</Suspense>
</section>

{/* Status Displays */}
Expand Down
21 changes: 21 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ export default defineConfig({
build: {
cssCodeSplit: false,
outDir: "dist",
rollupOptions: {
output: {
manualChunks(id) {
// Separate React + React DOM
if (id.includes("react") && (id.includes("node_modules/react") || id.includes("node_modules/react-dom"))) {
return "vendor-react";
}
// Separate TanStack Query
if (id.includes("@tanstack/react-query")) {
return "vendor-query";
}
// Separate wallet libraries
if (id.includes("node_modules/wagmi") || id.includes("node_modules/viem") || id.includes("@reown/appkit")) {
return "vendor-wallet";
}
},
chunkFileNames: "assets/[name]-[hash].js",
entryFileNames: "assets/[name]-[hash].js",
assetFileNames: "assets/[name]-[hash].[ext]",
},
},
},
worker: {
format: "es",
Expand Down
Loading