Communitygithub.com

Vercel React 最佳實踐

來自 Vercel Engineering 的 React 與 Next.js 效能優化指南。在撰寫、審查或重構 React/Next.js 程式碼時使用,以確保採用最佳效能模式。

Vercel React 最佳實踐 是什麼?

此技能是 Vercel 維護的 React 與 Next.js 完整效能優化指南,包含 8 個類別、45 條規則,並按影響程度排序。它適用於多種開發情境,例如建立新元件、實作資料擷取、進行程式碼審查或最佳化套件大小。支援 Vercel 生態系中的 React 與 Next.js 專案。其運作方式是透過提供具體、可執行的規則(例如對非同步操作使用 `Promise.all()`、動態匯入大型元件、使用 `useMemo()` 避免不必要的重新渲染),每個規則檔案都包含錯誤與正確的程式碼範例。開發者可以透過參考按優先順序整理的規則類別,快速找出最高回報的效能改善項目,這使得它成為撰寫生產等級 React/Next.js 程式碼的實用參考工具。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ASoudy/AGS/tree/HEAD/claude_skills_libraries/landing-page-mastery/skills/vercel-react-best-practices

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Vercel React 最佳實踐 是做什麼的?

由 Vercel 維護的 React 與 Next.js 應用程式完整效能優化指南。包含 45 條規則,橫跨 8 個類別,並根據影響程度排序,以引導自動重構與程式碼生成。

何時套用

在以下情況參考這些指南:

  • 撰寫新的 React 元件或 Next.js 頁面
  • 實作資料擷取(客戶端或伺服器端)
  • 審查程式碼以找出效能問題
  • 重構現有的 React/Next.js 程式碼
  • 最佳化套件大小或載入時間

規則類別(依優先順序)

優先順序類別影響程度前綴
1消除瀑布效應關鍵async-
2套件大小最佳化關鍵bundle-
3伺服器端效能高server-
4客戶端資料擷取中高client-
5重新渲染最佳化中rerender-
6渲染效能中rendering-
7JavaScript 效能低中js-
8進階模式低advanced-

快速參考

1. 消除瀑布效應(關鍵)

  • async-defer-await - 將 await 移到實際使用的分支中
  • async-parallel - 對獨立操作使用 Promise.all()
  • async-dependencies - 對部分相依使用 better-all
  • async-api-routes - 在 API 路由中盡早啟動 promise,延後 await
  • async-suspense-boundaries - 使用 Suspense 來串流內容

2. 套件大小最佳化(關鍵)

  • bundle-barrel-imports - 直接匯入,避免使用 barrel 檔案
  • bundle-dynamic-imports - 對大型元件使用 next/dynamic
  • bundle-defer-third-party - 在 hydration 完成後再載入分析/記錄功能
  • bundle-conditional - 僅在功能啟用時載入模組
  • bundle-preload - 在懸停/聚焦時預載入以提升感知速度

3. 伺服器端效能(高)

  • server-cache-react - 使用 React.cache() 進行每個請求的去重
  • server-cache-lru - 使用 LRU 快取進行跨請求快取
  • server-serialization - 最小化傳遞給客戶端元件的資料
  • server-parallel-fetching - 重構元件以平行化資料擷取
  • server-after-nonblocking - 使用 after() 進行非阻塞操作

4. 客戶端資料擷取(中高)

  • client-swr-dedup - 使用 SWR 進行自動請求去重
  • client-event-listeners - 去重全域事件監聽器

5. 重新渲染最佳化(中)

  • rerender-defer-reads - 不要訂閱只在回呼中使用的狀態
  • rerender-memo - 將耗時的工作提取到記憶化的元件中
  • rerender-dependencies - 在 effect 中使用基本型別作為相依性
  • rerender-derived-state - 訂閱衍生的布林值,而非原始值
  • rerender-functional-setstate - 使用函數式 setState 以獲得穩定的回呼
  • rerender-lazy-state-init - 對昂貴的初始值,傳遞函數給 useState
  • rerender-transitions - 對非緊急的更新使用 startTransition

6. 渲染效能(中)

  • rendering-animate-svg-wrapper - 對 div 包裝器進行動畫,而非 SVG 元素本身
  • rendering-content-visibility - 對長列表使用 content-visibility
  • rendering-hoist-jsx - 將靜態 JSX 提取到元件外部
  • rendering-svg-precision - 降低 SVG 座標精度
  • rendering-hydration-no-flicker - 使用內嵌 script 處理僅客戶端資料
  • rendering-activity - 使用 Activity 元件來控制顯示/隱藏
  • rendering-conditional-render - 使用三元運算子,而非 && 來進行條件渲染

7. JavaScript 效能(低中)

  • js-batch-dom-css - 透過 class 或 cssText 分組 CSS 變更
  • js-index-maps - 為重複查詢建立 Map
  • js-cache-property-access - 在迴圈中快取物件屬性
  • js-cache-function-results - 將函數結果快取在模組層級的 Map 中
  • js-cache-storage - 快取 localStorage/sessionStorage 的讀取結果
  • js-combine-iterations - 將多個 filter/map 合併為一個迴圈
  • js-length-check-first - 在進行昂貴的比較之前,先檢查陣列長度
  • js-early-exit - 在函數中及早返回
  • js-hoist-regexp - 將 RegExp 創建提升到迴圈外部
  • js-min-max-loop - 使用迴圈找出最小/最大值,而非 sort
  • js-set-map-lookups - 使用 Set/Map 進行 O(1) 查詢
  • js-tosorted-immutable - 使用 toSorted() 保持不可變性

8. 進階模式(低)

  • advanced-event-handler-refs - 將事件處理器儲存在 refs 中
  • advanced-use-latest - useLatest 用於穩定的回呼 refs

如何使用

閱讀個別規則檔案以取得詳細說明和程式碼範例:

rules/async-parallel.md
rules/bundle-barrel-imports.md
rules/_sections.md

每個規則檔案包含:

  • 規則重要性的簡要說明
  • 錯誤的程式碼範例及說明
  • 正確的程式碼範例及說明
  • 其他相關背景資訊與參考資料

完整彙編文件

如需包含所有規則展開的完整指南,請參閱:AGENTS.md

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ASoudy/AGS

Advanced JavaScript animation library skill for creating complex, high-performance web animations.

ASoudy/AGS

Astropy is the core Python package for astronomy, providing essential functionality for astronomical research and data analysis.

ASoudy/AGS

Build content-focused websites with Astro — zero JS by default, islands architecture, multi-framework components, and Markdown/MDX support.

ASoudy/AGS

One sentence - what this skill does and when to invoke it

ASoudy/AGS

Audit and fix animation performance issues including layout thrashing, compositor properties, scroll-linked motion, and blur effects. Use when animations stutter, transitions jank, or reviewing CSS/JS animation performance.

ASoudy/AGS

Internationalization and localization patterns. Detecting hardcoded strings, managing translations, locale files, RTL support.

ASoudy/AGS

Pull a YouTube video transcript into a queryable markdown vault with yt-dlp subtitle discovery, VTT cleanup, metadata frontmatter, and capture-seed stubs.

ASoudy/AGS

Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences. Covers developer portfolios, designer portfolios, creative portfolios, and portfolios that convert visitors into opportunities.

ASoudy/AGS

Generates high-converting Next.js/React landing pages with Tailwind CSS. Uses PAS, AIDA, and BAB frameworks for optimized copy/components (Heroes, Features, Pricing). Focuses on Core Web Vitals/SEO.

ASoudy/AGS

AI-powered animation tool for creating motion in logos, UI, icons, and social media assets.

ASoudy/AGS

CRITICAL: Use for Makepad animation system. Triggers on: makepad animation, makepad animator, makepad hover, makepad state, makepad transition, "from: { all: Forward", makepad pressed, makepad 动画, makepad 状态, makepad 过渡, makepad 悬停效果

ASoudy/AGS

Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.

ASoudy/AGS

Next.js App Router principles. Server Components, data fetching, routing patterns.

ASoudy/AGS

Expert integration of Supabase Auth with Next.js App Router

ASoudy/AGS

React and Next.js 14+ application development with App Router, Server Components, TypeScript, Tailwind CSS, and modern frontend patterns.

ASoudy/AGS

Best practices for Remotion - Video creation in React

ASoudy/AGS

Generate walkthrough videos from Stitch projects using Remotion with smooth transitions, zooming, and text overlays

ASoudy/AGS

Seek and analyze video content using Memories.ai Large Visual Memory Model for persistent video intelligence

ASoudy/AGS

Writes complete, structured landing pages optimized for SEO ranking, AEO citation, and visitor conversion. Activate when the user wants to write or generate a landing page for a product, service, or offer.

ASoudy/AGS

Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

相關技能