ssr-migration

将客户端渲染(CSR)的 React/Vue 应用迁移至服务端渲染(SSR)或静态站点生成(SSG),使用 Next.js、Nuxt 或 Astro 实现。适用于需要提升 SEO、降低首字节时间(TTFB)、解决爬虫抓取空白页或优化核心 Web 指标的场景,涵盖渐进式迁移、数据获取模式、注水(hydration)调试及部署配置。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "ssr-migration":https://skillpi.com/zh/skills/deepskill-e7cceb433f072e607e25c8830177a51960f18f3d7b19d72199bd531d4cebd317。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

将客户端渲染(CSR)的 React/Vue 应用迁移至服务端渲染(SSR)或静态站点生成(SSG),使用 Next.js、Nuxt 或 Astro 实现。适用于需要提升 SEO、降低首字节时间(TTFB)、解决爬虫抓取空白页或优化核心 Web 指标的场景,涵盖渐进式迁移、数据获取模式、注水(hydration)调试及部署配置。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: ssr-migration
description: >-
  Migrate client-side rendered (CSR) React/Vue applications to server-side
  rendering (SSR) or static site generation (SSG) using Next.js, Nuxt, or
  Astro. Use when you need to improve SEO, reduce time-to-first-byte, fix
  blank page issues for crawlers, or improve Core Web Vitals. Covers
  incremental adoption, data fetching patterns, hydration debugging, and
  deployment configuration. Trigger words: SSR, SSG, server-side rendering,
  static generation, Next.js migration, SEO, hydration, TTFB, Core Web Vitals.
license: Apache-2.0
compatibility: "Node.js 18+. React 18+ for Next.js, Vue 3+ for Nuxt 3."
metadata:
  author: terminal-skills
  version: "1.0.0"
  category: development
  tags: ["ssr", "ssg", "nextjs", "performance", "seo"]

SSR Migration

Overview

This skill guides the migration of client-side rendered single-page applications to server-side rendering or static site generation. It covers the incremental migration strategy (not a rewrite), identifying which pages benefit from SSR vs SSG vs CSR, fixing hydration mismatches, adapting data fetching patterns, and configuring deployment for SSR workloads.

Instructions

1. Audit the current CSR application

Identify what needs to change before migrating:

# Check for SSR-incompatible patterns:
# 1. Direct window/document access at module level
grep -rn "window\." src/ --include="*.tsx" --include="*.ts" | grep -v "typeof window"

# 2. Browser-only libraries imported at top level
grep -rn "import.*from.*('|\")(chart.js|swiper|mapbox)" src/

# 3. localStorage/sessionStorage usage outside useEffect
grep -rn "localStorage\|sessionStorage" src/ --include="*.tsx"

# 4. Dynamic imports that should stay client-only
grep -rn "React.lazy\|dynamic(" src/ --include="*.tsx"

Classify each page by rendering strategy:

  • SSG — content changes rarely, same for all users (marketing pages, blog posts, docs)
  • SSR — content changes frequently or is user-specific (dashboards, search results)
  • CSR — highly interactive, no SEO need (admin panels, internal tools)

2. Set up Next.js App Router alongside existing code

Migrate incrementally using Next.js App Router:

// app/products/page.tsx — SSG with revalidation
export const revalidate = 3600; // Regenerate every hour

async function getProducts() {
  const res = await fetch("https://api.example.com/products", {
    next: { revalidate: 3600 },
  });
  return res.json();
}

export default async function ProductsPage() {
  const products = await getProducts();
  return (
    <main>
      <h1>Products</h1>
      <ProductGrid products={products} />
    </main>
  );
}

// app/products/[id]/page.tsx — SSG with dynamic params
export async function generateStaticParams() {
  const products = await fetch("https://api.example.com/products").then(r => r.json());
  return products.map((p: { id: string }) => ({ id: p.id }));
}

export default async function ProductPage({ params }: { params: { id: string } }) {
  const product = await fetch(`https://api.example.com/products/${params.id}`).then(r => r.json());
  return <ProductDetail product={product} />;
}

3. Handle hydration mismatches

The most common migration bugs are hydration errors:

// BAD — different output on server vs client
function Greeting() {
  return <p>Current time: {new Date().toLocaleTimeString()}</p>;
}

// GOOD — defer client-only content
"use client";
import { useState, useEffect } from "react";

function Greeting() {
  const [time, setTime] = useState<string | null>(null);
  useEffect(() => {
    setTime(new Date().toLocaleTimeString());
  }, []);
  return <p>Current time: {time ?? "Loading..."}</p>;
}

4. Migrate data fetching patterns

// BEFORE (CSR): useEffect + useState
function Dashboard() {
  const [data, setData] = useState(null);
  useEffect(() => {
    fetch("/api/dashboard").then(r => r.json()).then(setData);
  }, []);
  if (!data) return <Spinner />;
  return <DashboardView data={data} />;
}

// AFTER (SSR): Server Component with async/await
async function Dashboard() {
  const data = await fetch("http://internal-api/dashboard", {
    headers: { cookie: cookies().toString() },
  }).then(r => r.json());
  return <DashboardView data={data} />;
}

5. Configure deployment for SSR

# Dockerfile for Next.js SSR
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public
EXPOSE 3000
CMD ["node", "server.js"]

Examples

Example 1: Marketing site migration

Prompt: "Migrate our React SPA marketing site to Next.js with SSG. We have 12 pages: homepage, 5 product pages, pricing, about, blog listing, blog posts (40 articles), contact, and FAQ."

Agent output:

  • Creates Next.js App Router structure with static pages for homepage, pricing, about, contact, FAQ
  • Blog listing and posts use generateStaticParams + ISR (revalidate every 30 minutes)
  • Product pages use SSG with on-demand revalidation via webhook
  • Identifies 3 components using window directly — wraps them in dynamic imports with ssr: false
  • Adds next-sitemap configuration for automatic XML sitemap generation

Example 2: Dashboard with mixed rendering

Prompt: "Our React dashboard app needs SSR for the main feed (SEO matters) but the settings and admin pages can stay client-rendered. How do I set this up incrementally?"

Agent output:

  • Creates app/(public)/feed/page.tsx as a Server Component with SSR
  • Creates app/(private)/settings/page.tsx with "use client" directive, keeping existing CSR logic
  • Adds middleware for authentication that redirects unauthenticated users before SSR runs
  • Migrates the feed's useEffect data fetching to server-side fetch with cookie forwarding
  • Keeps the real-time notification widget as a Client Component embedded within the SSR layout

Guidelines

  • Migrate incrementally — move one route at a time, not the entire app at once.
  • Start with SSG pages — they're the easiest win and don't require a Node.js server.
  • Use "use client" sparingly — only for components that genuinely need browser APIs or interactivity.
  • Test hydration in development — React 18's strict mode double-renders to catch mismatches early.
  • Forward cookies for authenticated SSR — server-side fetch won't include user cookies automatically.
  • Monitor TTFB after migration — SSR adds server computation time. If TTFB increases, consider caching or ISR.
  • Keep bundle size in check — SSR doesn't eliminate the need for code splitting. Use dynamic imports for heavy client components.

当前收录版本

1.0.0

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值92/100

亮点

  • 解决前端开发中SSR/SSG迁移的核心痛点
  • 覆盖SEO优化、TTFB降低、爬虫抓取等关键场景
  • 提供渐进式迁移策略,降低实施风险
触发精准95/100

亮点

  • 触发词覆盖SSR/SSG相关术语及具体技术栈
  • 边界清晰,不易与其他Skill重叠
  • 包含核心Web指标等专业术语
结构规范90/100

亮点

  • Phase/步骤清晰,有明确的出口条件
  • 包含端到端示例,便于理解执行流程
  • frontmatter完整,单文件结构良好
执行可靠88/100

亮点

  • 工具来源明确,参数正确
  • 覆盖主要异常,如hydration mismatch处理
  • 不可逆操作有确认机制,如渐进式迁移策略
证据可验 (前四项均值)91/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

文档引用的域名或地址

这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。

  • api.example.com
  • internal-api

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。