返回 AiToEarn
bundle-defer-third-party.md
根目录 / project / aitoearn-web / .agents / skills / vercel-react-best-practices / rules / bundle-defer-third-party.md
1 ---
2 title: Defer Non-Critical Third-Party Libraries
3 impact: MEDIUM
4 impactDescription: loads after hydration
5 tags: bundle, third-party, analytics, defer
6 ---
7
8 ## Defer Non-Critical Third-Party Libraries
9
10 Analytics, logging, and error tracking don't block user interaction. Load them after hydration.
11
12 **Incorrect (blocks initial bundle):**
13
14 ```tsx
15 import { Analytics } from '@vercel/analytics/react'
16
17 export default function RootLayout({ children }) {
18 return (
19 <html>
20 <body>
21 {children}
22 <Analytics />
23 </body>
24 </html>
25 )
26 }
27 ```
28
29 **Correct (loads after hydration):**
30
31 ```tsx
32 import dynamic from 'next/dynamic'
33
34 const Analytics = dynamic(
35 () => import('@vercel/analytics/react').then(m => m.Analytics),
36 { ssr: false }
37 )
38
39 export default function RootLayout({ children }) {
40 return (
41 <html>
42 <body>
43 {children}
44 <Analytics />
45 </body>
46 </html>
47 )
48 }
49 ```
50
50 lines MARKDOWN