Communitygithub.com

BIGboss248/nextjs-wordpress

建立 Next.js App Router React 元件,包含 Suspense 骨架、語意化 OKLCH 代號、Jest + RTL 單元測試、Playwright 視覺/渲染一致性檢查,以及 Tailwind 邏輯屬性樣式。觸發指令為「/nextjs-component-dev」、「create component」、「new component」、「build component」或「develop component」。

nextjs-wordpress 是什麼?

此技能提供一個專門的工作流程,用於建立準備上線的 Next.js React Server Components (RSC) 與 Client Components,並包含 Suspense 骨架、雙層 TDD 測試(Jest + RTL 單元測試與 Playwright 整合/渲染一致性/視覺檢查)、next-intl 字典驅動的翻譯、語意化主題代號,以及透過 next-devtools MCP 進行的即時運行診斷。它支援 Claude Code、Coder 和 Cursor 等平台,透過搜尋本地 `node_modules/next/dist/docs` 文件來確保程式碼準確,避免使用已棄用的模式。此技能強調精細的 Suspense 邊界、使用 Tailwind 邏輯屬性(ms-、pe- 等)的雙向(BiDi)樣式,以及包含即時導航、快取策略(使用「use cache」搭配 cacheLife/cacheTag)和預先擷取(prefetching)的架構。它會建立一個執行計畫 (`implementation_plan.md`),在使用者核准後,才會在 `<new_component_dir>/<page_or_global>/<ComponentName>/` 路徑下建立檔案,並使用 CSS 變數(避免使用硬編碼的色碼)進行樣式設定。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/BIGboss248/nextjs-wordpress/tree/HEAD/.agents/skills/nextjs-component-dev

在你喜歡的 AI 中提問

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

說明文件

Next.js 元件與骨架開發 (nextjs-component-dev)

專業工作流程,用於建立準備上線的 React Server Components (RSC) 和 Client Components,包含 Suspense 骨架、雙層 TDD 測試(Jest + RTL 單元測試和 Playwright 整合/渲染一致性/視覺檢查)、next-intl 字典驅動的翻譯、語意化主題代號,以及透過 next-devtools MCP 進行的即時運行診斷。

[!TIP] 模組化資產與範本:


架構規則與標準

1. 規劃脈絡與路徑

  • 讀取 docs/project.json 以解析 package_manager、new_component_dir、style_file_dir、component_library、dictionaries_dir(預設值:"messages")和 supported_languages。
  • 所有內部路由都必須使用來自 @/lib/routes 的 ROUTES。
  • 所有作者/網站元資料都必須使用來自 @/lib/site-config 的 SITE_CONFIG。
  • 目標路徑階層:<new_component_dir>/<page_or_global>/<ComponentName>/
    • 類別:global/ 用於共享佈局外框;<page-name>/(例如 home/、about/、lab/)用於頁面範圍的區段。

2. Next.js 內部文件查詢(node_modules/next/dist/docs)

  • 透過 Codebase Memory MCP 搜尋本地文件: 對於任何元件建立,都應使用 codebase-memory MCP 工具(search_code、search_graph、get_code_snippet)主動查詢並檢查位於 node_modules/next/dist/docs/ 的本地 Next.js 發行文件,以取得相關的 API 簽章、指令('use cache'、'use client'、'use server')、內建元件(next/image、next/link、next/font、<Form>)、導航鉤子(useRouter、usePathname)以及快取策略(cacheLife、cacheTag)。
  • 消除已棄用項目與幻覺: 切勿依賴假設或過時的 Next.js 模式;與已安裝套件版本相符的本地 node_modules/next/dist/docs 是主要的事實來源。請參閱 references/nextjs-docs-lookup.md。

3. 開發伺服器與 Next DevTools 協定

  • 開發伺服器檢查與接入: 在元件開發期間,透過 next-devtools MCP 伺服器(nextjs_index)檢查 Next.js 開發伺服器是否正在執行。
  • 如果伺服器正在執行: 立即接入正在執行的伺服器和連接埠;不要重新啟動。
  • 如果伺服器未執行: 在背景啟動開發伺服器(pnpm dev、IsDaemon: true)並透過 nextjs_index 驗證連線。
  • 運行時除錯: 實作元件後,立即查詢 next-devtools(nextjs_call)以檢查錯誤、檢查建置狀態並診斷運行時問題。請參閱 references/next-devtools-debugging.md。

4. RSC 邊界與葉端 Client 下推

  1. 預設為伺服器元件: 保持元件為伺服器渲染(async function)。
  2. 將 "use client" 下推: 將互動式處理常式(按鈕、切換開關、表單輸入)隔離到小的葉端 Client Components 中。
  3. RSC 組合: 將 Server Components 作為 children 或 props 傳入 Client 包裝器中。切勿在 "use client" 檔案內匯入 Server Components。

5. 樣式、邏輯屬性與主題代號

  • 語意化代號: 僅使用在 app/globals.css 中定義的語意化 CSS 變數(bg-background、text-foreground、border-border、text-muted-foreground)。禁止使用硬編碼的十六進位色碼(#FAFAFA)或原始顏色比例(bg-blue-500)。
  • 類別合併: 始終使用 cn(...)(clsx + tailwind-merge)合併類別。
  • 邏輯屬性(BiDi): 僅使用 Tailwind 邏輯屬性(ms-、pe-、ps-、me-、start、end)。禁止使用實體方向類別(ml-、mr-、pl-、pr-、left-、right-)。
  • 進度連結: 使用來自 @vercel/react-transition-progress 的 <Link> 作為主要導航、英雄行動呼籲和互動式卡片;對於靜態工具連結則使用標準的 next/link。
  • 圖片: 始終使用 next/image,並指定明確尺寸或 fill、回應式 sizes,以及針對上方折疊 LCP 資產使用 priority。

6. 即時導航、精細 Suspense 與快取架構

  • 即時元件的三個槓桿:
    1. 下推:將請求特定的非同步操作(await params、await searchParams、cookies()、headers()、未快取的資料庫/API 呼叫)提取到包在 <Suspense> 中的葉端子元件中。靜態父層與兄弟層直接提升到靜態/應用程式殼層(App Shell)。
    2. 快取:在函式/元件層級將 'use cache' 與 cacheLife 和 cacheTag 配對使用。使用工作階段橋接模式:
      • 模式 A(提取與傳遞):從外部的 cookies() 提取工作階段屬性(例如 team_id、role、tier),並作為參數傳遞給 'use cache' 函式,使得快取資料能在所有具有匹配屬性的使用者之間共享(成本隨團隊/屬性數量擴展,而非使用者工作階段數量)。
      • 模式 B("use cache: private"):對於嚴格限於使用者的工作階段查詢,使用瀏覽器專用的工作階段快取,且 stale >= 5m,並隨應用程式殼層一起傳遞。
    3. 預先擷取策略與密集網格:
      • 預設應用程式殼層預先擷取(<Link> / prefetch={null}):每個路由預先擷取一個共享的靜態/應用程式殼層。成本有上限($O(\text{routes})$),每個連結零伺服器呼叫。用於密集饋送、卡片網格(50 張卡片以上)和大量導覽。
      • 每連結預先擷取(<Link prefetch={true}>):在導覽前以每個可見連結 1 次伺服器呼叫解析動態 URL 資料(params、searchParams)。謹慎使用於高意圖的主要行動呼籲、英雄動作或主從列表項目,以消除骨架閃爍。
      • 密集卡片網格:切勿在饋送中的數十張卡片上全面使用 prefetch={true}。保留預設的 <Link> 或使用懸停/聚焦意圖預先擷取(router.prefetch())。
  • 精細載入狀態(防止全頁閃爍):切勿將整個元件或頁面包在單一頂層的 <Suspense> 邊界中,這會導致整個骨架閃爍。讓標題、佈局框架和快取內容立即可見;僅將 <Suspense> 嚴格放置在動態串流插槽周圍。
  • 原生 Next.js 16 快取指令:請參閱 references/instant-navigation-and-prefetching.md 和 references/caching-and-revalidation.md。

7. TanStack Query 與伺服器預先擷取

  • 統一快取合約: 定義 key、tag 和 queryOptions,並加上明確的 staleTime(例如 30_000 毫秒)。
  • 伺服器預先擷取: 觸發非等待的預先擷取(void queryClient.prefetchQuery(...)),直接呼叫內部資料庫函式(伺服器上零相對擷取)。使用 <HydrationBoundary> 進行解水合。
  • 串流元件: 在 <Suspense fallback={<[ComponentName]Skeleton />}> 內部使用 useSuspenseQuery。
  • 樂觀突變: 使用 useMutation,搭配 onMutate 快取快照和 onError 回滾;使用 updateTag(cache.tag) 呼叫伺服器動作。

8. 雙層測試分工(Jest vs. Playwright)

  • Jest + RTL([ComponentName].test.tsx):
    • 在 jsdom 中快速回饋迴圈。
    • Prop 排列組合、條件式 UI 元素以及空值/無效狀態。
    • 透過 @testing-library/user-event 進行使用者互動(絕不使用 fireEvent)。
    • Next.js 路由模擬(來自 next/navigation 的 useRouter、usePathname、useSearchParams)。
    • 在 NextIntlClientProvider 內部進行 next-intl 字典插值與複數化檢查。
    • 可訪問的角色查詢(screen.getByRole)與自動化的 a11y 檢查(jest-axe)。
  • Playwright([ComponentName].spec.ts 或頁面層級規格):
    • 真實瀏覽器執行(Chromium/WebKit/Firefox)。
    • 即時殼層斷言(@next/playwright): 使用 instant(page, ...) 輔助函式,在動態伺服器串流解析前,斷言靜態殼層和預先擷取的應用程式殼層會立即渲染。
    • 零渲染不一致: 監聽瀏覽器控制台事件(page.on('console')),以偵測 React SSR 水合警告,並使測試失敗。
    • 視覺與 BiDi 回歸: 使用 expect(page).toHaveScreenshot() 跨主題(淺色與深色 OKLCH 變數)和文字方向(dir="ltr" 與 dir="rtl")進行測試。
    • 網路彈性: 使用 page.route() 測試慢速網路回應(驗證 Suspense 骨架幾何形狀以防止 CLS)和 500 錯誤邊界。
  • 詳細測試標準: 請參閱 references/testing-architecture-guide.md。

階段 0:實作計畫與核准閘門

[!IMPORTANT] 先計畫再執行: 在執行任何寫入操作、修改字典或建立元件之前,務必先產生並呈現一個 implementation_plan.md 構件,詳細說明所有計劃的檔案建立、修改、TypeScript 合約、翻譯字典新增內容以及 TDD 測試案例。等待使用者確認/核准後再繼續執行。

實作計畫必須涵蓋:

  1. 目標架構與路徑:完整目標目錄(<new_component_dir>/<page_or_global>/<ComponentName>/)與分類(RSC 與 Client 葉端元件)。
  2. 查閱的 Next.js 本地文件:在 node_modules/next/dist/docs/ 下檢查的特定文件路徑(例如 04-api-reference/04-components/image.md、03-directives/use-cache.md、04-api-reference/02-functions/use-router.md)。
  3. TypeScript 合約:Prop 介面與型別,並附帶嚴格的英文 TSDoc 註解。
  4. 字典策略:明確的翻譯命名空間與金鑰,需新增至 docs/project.json 中所有 supported_languages 的 messages/[locale].json 檔案(零硬編碼字串或檔案內模擬字典)。
  5. 主題代號與樣式:識別出的語意化 OKLCH CSS 變數與邏輯佈局類別。
  6. 測試與診斷策略:
    • Jest 單元測試([ComponentName].test.tsx):模擬配置(next/navigation)、prop 變化、回呼斷言、NextIntlClientProvider 整合以及 a11y 角色查詢。
    • Playwright 整合情境([ComponentName].spec.ts):視覺快照目標(淺色/深色主題代號、LTR 與 RTL 邏輯佈局)、網路節流/骨架幾何檢查以及水合驗證監聽器。
    • Next DevTools 診斷:透過 next-devtools 進行運行時錯誤與編譯檢查。
  7. 驗證閘門:要執行的確切驗證指令(verify-dev.ps1、目標單元測試以及 Playwright e2e 規格)。

工作流程步驟

  • 步驟 0:實作計畫產生與核准閘門

    • 透過 codebase-memory MCP(search_code、search_graph)搜尋並檢查 node_modules/next/dist/docs,以取得計劃元件所使用的任何 Next.js API、指令、鉤子或元件的最新脈絡。
    • 綜合元件需求、掃描 docs/project.json,並產生 implementation_plan.md,記錄已查閱的文件與合約。
    • 在構件上設定 request_feedback = true 和 user_facing = true。
    • 等待使用者審查並明確核准後,再撰寫任何程式碼。
  • 步驟 1:開發伺服器驗證與 Next DevTools 連線

    • 透過 nextjs_index 查詢 next-devtools MCP,以偵測正在執行的 Next.js 開發伺服器實例。
    • 如果開發伺服器正在執行: 接入使用中的連接埠和伺服器實例;繼續開發而不重新啟動。
    • 如果開發伺服器未執行: 在背景啟動開發伺服器(pnpm dev、IsDaemon: true),並使用 nextjs_index 驗證發現。
  • 步驟 2:字典填入與 TypeScript 合約定義

    • 讀取 docs/project.json 以解析 dictionaries_dir(messages 為預設值)和 supported_languages。
    • 定義元件的翻譯命名空間和金鑰。
    • 在撰寫 JSX 之前,以真實的翻譯填入所有字典檔案(messages/en.json、messages/fa.json 等),涵蓋每種支援的語言。
    • 使用嚴格的英文 TSDoc 註解(@param、@defaultValue、@returns)定義 prop 介面。
    • 如果支援的語言超過一種,元件必須先取得翻譯,如果失敗則使用備用方案。
  • 步驟 3:TDD 基準單元測試(透過 Jest + RTL 的 [ComponentName].test.tsx)

    • 在實作元件之前撰寫 [ComponentName].test.tsx。
    • 模擬 next/navigation 鉤子(useRouter、usePathname、useSearchParams)。
    • 在 NextIntlClientProvider 中包裝渲染的元件,並提供字典 messages 和啟用的 locale。
    • 測試方向屬性(dir="rtl" 與 dir="ltr")、預設 props、互動式回呼(@testing-library/user-event)、Suspense 骨架備用內容以及語意化 ARIA 角色。
  • 步驟 4:元件、骨架與 E2E 規格實作

    • 建立目標元件目錄結構:<new_component_dir>/<page_or_global>/<ComponentName>/。
    • 實作元件([ComponentName].tsx):
      • 無狀態 RSC 使用 async function 直接渲染。
      • 互動式葉端 Client 在頂端加入 'use client'。
      • 匯入 @/lib/routes 與 @/lib/site-config。
      • 使用來自 /app/globals.css 的語意化 CSS 變數和邏輯 Tailwind 屬性。
      • 使用 next-intl 的 useTranslations()(Client)或 getTranslations()(Server)。
      • 使用 cn() 合併類別。使用符合語意的 <nav>、<section>、<article>、<aside> 標籤。
    • 實作骨架([ComponentName]Skeleton.tsx):
      • 比對最終元件的幾何形狀(寬度、高度、間距)。
      • 使用 Tailwind 動畫類別(animate-pulse、rounded-md、bg-muted)。
      • 使用語意化 ARIA 屬性(role="status"、aria-label="Loading [ComponentName]")。
    • 玩美規格實作。
    • 在 Playwright 規格中使用 instant(page, ...) 進行即時殼層斷言。
  • 步驟 5:Playwright E2E 規格實作([ComponentName].spec.ts)

    • 在步驟 4 之後撰寫規格。
    • 測試靜態殼層立即渲染。
    • 模擬慢速網路以驗證骨架幾何形狀。
    • 在多個主題上進行視覺快照測試。
    • 在 LTR 與 RTL 文字方向上測試邏輯間距。
    • 測試錯誤與邊界情況(例如 API 500 錯誤)。
  • 步驟 6:Next DevTools 診斷與驗證

    • 使用 nextjs_query 執行運行時檢查。
    • 驗證在建置/編譯期間無錯誤。
    • 驗證任何路由的渲染方式和原因。

觸發模式

此技能由以下使用者訊息模式觸發:

  • /nextjs-component-dev
  • create component
  • new component
  • build component
  • develop component
  • 任何結合實作 Next.js 元件與骨架支援的意圖,如上述步驟所述。

參考資料

  • 請參閱 references/ 目錄以取得詳細指南。
  • 請參閱 resources/templates/ 以取得程式碼範本。
  • 請參閱 examples/ 以取得參考實作。
  • 請參閱 scripts/ 以取得驗證腳本。

Individual skills in this repo

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

BIGboss248/nextjs-wordpress

Create, configure, manage, and validate Google Antigravity customizations including skills, rules, MCP servers, lifecycle hooks, plugins, and custom JSON configs. Use when adding new capabilities to Antigravity, configuring MCP servers, writing rules, creating skills, setting up hooks, or modernizing legacy workflows.

BIGboss248/nextjs-wordpress

Spawn multiple agents into a shared conversation where they debate, disagree, and converge on a solution via a shared chat.json file. Use for architecture decisions, code review debates, design trade-offs, or any problem that benefits from adversarial reasoning. Triggers on "chatroom", "agent debate", "have agents discuss", "agent chatroom", "debate this", or /agent-chatrooms. Also triggers on phrases like "have 3 agents argue about", "multi-agent discussion", or "let them debate".

BIGboss248/nextjs-wordpress

Always-active code intelligence, search, and navigation skill utilizing the codebase-memory MCP server. Enforces an index-first protocol (verifying and refreshing the knowledge graph via index_repository or index_status before searching, required because background auto_watch is disabled to eliminate editor stutter and system lag), followed by graph-first exploration (search_graph, trace_path, get_code_snippet, query_graph, get_architecture, detect_changes) instead of naive text grep or full-file reads. Always activate before searching the codebase, inspecting unknown architecture, finding symbols, or tracing callers/callees.

BIGboss248/nextjs-wordpress

>- Discover, interview, and craft comprehensive UX/UI design specifications (design-spec.md) and design tokens for web components. Triggers on "/component-design", "design component", "design section", "design UI", "wireframe component", or "create design spec".

BIGboss248/nextjs-wordpress

>- Configure and query WooCommerce APIs including WPGraphQL, WooGraphQL, and JWT auth for headless frontends. Use when connecting Next.js to WooCommerce or fetching store catalog data.

BIGboss248/nextjs-wordpress

Orchestrate parallel browser automation using multiple Chrome DevTools MCP instances. Use when a task requires doing the same browser action across many targets simultaneously (e.g., submitting contact forms, filling applications, scraping pages that need JS rendering). Spin up 1-5 parallel Chrome agents.

BIGboss248/nextjs-wordpress

Workflow for spawning an independent subagent to conduct unbiased code reviews and inject adversarial edge-case tests ([ComponentName].edge.test.tsx).

BIGboss248/nextjs-wordpress

>- Bootstrap, configure, and verify the complete Next.js App Router development environment, developer tooling, testing suites, MCP servers, Docker containerization, and CI/CD. Triggers on "/nextjs-dev-setup", "setup nextjs dev environment", "start a nextjs project", or "containerize nextjs app".

BIGboss248/nextjs-wordpress

>- Configure production health monitoring endpoints (/api/health), Docker Compose probes, and runtime metrics in Next.js App Router applications. Use when asked to "setup health check", "add health endpoint", "docker compose healthcheck nextjs", "configure health monitor", or "/nextjs-healthcheck".

BIGboss248/nextjs-wordpress

Bootstrap, configure, and verify next-intl App Router internationalization (proxy.ts/middleware.ts, next/root-params, [locale] layout, routing). Triggers on "/nextjs-i18n-setup", "setup i18n", "install next-intl", "configure next-intl", "add internationalization", "setup locale routing", "migrate to [locale]".

BIGboss248/nextjs-wordpress

Read/write translation dictionaries (messages/[locale].json), next-intl hooks (getTranslations/useTranslations), providers (Storybook/tests/subtrees), and BiDi styling. Triggers on "/nextjs-i18n-usage", "i18n dictionary", "use translations", "read dictionary", "i18n provider", "next-intl hooks", "storybook i18n", "test i18n", "add translation keys", "localize component", "create a component", "update a component".

BIGboss248/nextjs-wordpress

>- Configure, test, and verify OpenTelemetry (OTel) observability in Next.js App Router applications. Triggers on "/nextjs-otel", "setup otel", "configure opentelemetry", "test otel", or "verify opentelemetry".

BIGboss248/nextjs-wordpress

Step-by-step workflow for designing and building Next.js App Router pages (RSC page.tsx, loading skeleton, metadata, JSON-LD schema, and dynamic static params). Triggers on "/nextjs-page-dev", "create page", "new page", "develop page", "build route", or "implement page".

BIGboss248/nextjs-wordpress

>- Orchestrate end-to-end planning for Next.js App Router projects, generating canonical specifications, design systems, and a 7-phase modular implementation roadmap in docs/plan/. Triggers on "/nextjs-plan", "plan a nextjs project", "plan nextjs app", "create nextjs project plan", "outline nextjs architecture", or "generate plan".

BIGboss248/nextjs-wordpress

Workflow and engineering standards for crafting co-located Storybook CSF3 stories ([ComponentName].stories.tsx) with interactive controls, action spies, and 4 canonical theme variants.

BIGboss248/nextjs-wordpress

>- Build Next.js e-commerce frontends backed by WooCommerce APIs, handling ISR catalogs, cart sessions, and JWT authentication. Use when building or querying Next.js stores with WooCommerce.

BIGboss248/nextjs-wordpress

Self-correcting rules engine and feedback loop that learns from user corrections, mistakes, and project-specific constraints by maintaining a persistent autofix ruleset. Scans learned rules before starting any task, resolves conflicts, and automatically appends new rules upon corrections. Triggers on user corrections ("no, do it this way", "never do X", "always use Y"), /learn, "self repair", "add rule", "update rules", or when diagnosing assumptions and bugs. CRITICAL ALWAYS-ACTIVE LIFECYCLE SKILL. Must always be kept in context, loaded at session start, and consulted before starting ANY task to read and apply active constraints from autofix.json. MUST ALWAYS be triggered immediately whenever the user provides ANY correction, preference, criticism, rejection of an approach, or adjustment ("no", "don't do X", "use Y", "remember", "prefer"), or when any mistake/bug is identified. Automatically and immediately formulates and appends the new imperative rule to the project's autofix.json ruleset file.

BIGboss248/nextjs-wordpress

Setup, automate, and execute SEO audits, CI/CD pre-push/pre-deploy checks, and ranking optimizations using the seo CLI and MCP server.

BIGboss248/nextjs-wordpress

End-to-end repository onboarding and development environment setup skill. Scans repository structure, configures project metadata (docs/project.json), sets up the codebase-memory-mcp code intelligence knowledge graph server (in workspace mcp.json and globally for AGY only), configures git hooks with Husky and Commitlint, establishes multi-stage production Docker containerization, and automates credit-optimized Release Please CI/CD with multi-arch (AMD64 & ARM64) GHCR package deployment. Triggers on "/setup-repository", "setup repository", "setup repo", "initialize repository", "new repo setup", or when preparing any repository for development and AI agent workflows.

BIGboss248/nextjs-wordpress

AI screen scaffolding, layout generation, and variant exploration workflow powered by Google Stitch (StitchMCP). Consumes a component design specification (docs/design/components/[page name]/[component name]/design-spec.md), verifies and reuses the central Stitch project in docs/project.json (or creates/persists one if absent), seeds the project's design system into Stitch, synthesizes layout prompts to generate a screen and create one variant of the given design spec file, downloads and saves Stitch JPG screenshots and HTML code files directly into docs/design/components/[page name]/[component name]/stitch/ using binary-safe PowerShell Invoke-WebRequest, outputs image prompts to the user if visual assets are needed (without calling generate_image to conserve tokens), updates design-spec.md with Stitch layout benchmarks, and audits asset download integrity with an independent subagent. Triggers on "/stitch-design", "generate stitch screen", "create stitch variant", "scaffold screen with stitch", or "stitch...

相關技能