## Summary - Replaces static import of `LineProfilerView` with `next/dynamic` + `ssr: false` - Defers loading of `prism-react-renderer` (~100KB+) until user navigates to profiler tab - Adds `<Skeleton>` loading fallback for smooth UX ## Evidence - Proof doc: `js/cf-webapp/proof/13-dynamic-import-line-profiler.md` ## Test plan - [ ] `bash js/cf-webapp/proof/reproducers/13-dynamic-import-line-profiler.sh` — 7/7 checks pass - [ ] `npm run build` succeeds - [ ] Profiler page loads and renders LineProfilerView correctly
1.2 KiB
1.2 KiB
Proof 13: Dynamic-import LineProfilerView
What Changed
- Replaced static import of
LineProfilerViewwithnext/dynamicin the profiler page - Added
ssr: falsesince the component uses browser-only APIs - Added
<Skeleton>loading fallback
Why
LineProfilerView depends on prism-react-renderer, which pulls in Prism.js grammar definitions (~100KB+). By using next/dynamic with ssr: false:
- The profiler page's initial JS bundle shrinks — Prism grammars are loaded on-demand
- The component only loads when the user navigates to the profiler tab, not on initial page load
- SSR is skipped for a component that relies on client-side rendering anyway
Evidence
Before (static import)
import { LineProfilerView } from "@/components/LineProfiler"
After (dynamic import)
import dynamic from "next/dynamic"
import { Skeleton } from "@/components/ui/skeleton"
const LineProfilerView = dynamic(
() => import("@/components/LineProfiler").then(mod => mod.LineProfilerView),
{
ssr: false,
loading: () => <Skeleton className="h-full w-full" />,
},
)
How to Verify
cd js/cf-webapp
bash proof/reproducers/13-dynamic-import-line-profiler.sh