Logo Nextjs Rsc To React Router V8 Migration

Nextjs Rsc To React Router V8 Migration

Cộng đồng
Innei
nextjs-rsc-to-react-router-v8-migration

Dùng khi chuyển một website Next.js RSC / App-Router hỗ trợ nhiều locale sang React Router v8 để HTML do SSR tạo ra có thể được CDN lưu vào bộ nhớ đệm. Payload RSC không thể được lưu vào bộ nhớ đệm ở edge, còn số locale × số trang làm tăng chi phí. Bao gồm các bước theo thứ tự: loại bỏ biến thiên SSR theo UA/geo/cookie, tách loader `.data` khỏi các yêu cầu fetch phía client, thiết lập lại SSR cho theme (next-themes + script head + /theme-vars.css), tách middleware thành Vercel Routing Middleware + bản sao root loader, prerender nội dung tĩnh và thiết lập Cache-Control 3 tầng để Cloudflare quản lý bộ nhớ đệm.

Add to TypingMind

Tổng quan

Nhà phát hànhInnei
Kho mãSKILL
Tên kỹ năngnextjs-rsc-to-react-router-v8-migration
Sao
81
Bản fork
2
Tệp đi kèm
3
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 3 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được Innei công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Nextjs Rsc To React Router V8 Migration trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/Innei/SKILL/tree/main/skills/infrastructure/nextjs-rsc-to-react-router-v8-migration
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Innei/SKILL.git /tmp/SKILL
mkdir -p .claude/skills
cp -r /tmp/SKILL/skills/infrastructure/nextjs-rsc-to-react-router-v8-migration .claude/skills/nextjs-rsc-to-react-router-v8-migration
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Nextjs Rsc To React Router V8 Migration trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Nextjs Rsc To React Router V8 Migration ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Nextjs Rsc To React Router V8 Migration với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

nextjs-rsc-to-react-router-v8-migration

Migrate a multi-locale Next.js RSC / App-Router site to React Router v8 so its SSR HTML is CDN-cacheable at the edge. The migration is not a "framework swap" — it is a cache-frame swap. RSC payload is per-request, per-cookie, per-header, and Vercel-only. RR8 gives you plain SSR HTML that Cloudflare can hold for hours if the response varies only by URL. The whole workflow enforces that invariant.

The gain is real only when locale × page multiplies the bill. On a 17-locale marketing surface with dynamic OG, sitemaps, and marketplace pages, RSC payload cost dominates even under ISR. RR8's plain SSR wins because the CDN can bypass origin for anonymous traffic.

When to use

  • Multi-locale (≥ 5 locales) SSR site whose RSC payload / ISR bill is a measurable cost driver.
  • Anonymous traffic dominates — the CDN can serve the same HTML to everyone in the same locale.
  • Team can absorb a phased cut: leave 3–5 URL groups on the legacy Next site behind for later ports (privacy/terms, growth pages, …).
  • CDN in front is Cloudflare (or any CDN that honours Cloudflare-CDN-Cache-Control). Vercel-CDN-only stacks lose the point — Vercel CDN cannot cache HTML that varies by cookie.

When NOT to use

  • Small site — RSC payload cost is a rounding error; keep Next.
  • Heavy Server Components composition — RR8 has no RSC. If your product surface is dashboard-shaped and you rely on RSC boundaries for streaming/composition, this trade is a loss.
  • SSR that legitimately varies per-user (dashboards, auth-gated pages) — CDN caching is moot; the migration only pays for anonymous surfaces.
  • Vercel CDN is the only CDN and you cannot bring Cloudflare in front.

Scope

  • Marketing / blog / marketplace-style SSR pages, multi-locale.
  • Loader-driven data fetch, most of which can move to client-side after hydration.
  • CSS-in-JS with SSR extraction (antd-style / emotion / stitches).
  • Middleware doing locale redirects, UA detection, geo hints.

Files

  • references/cache-control-profiles.md — the seven header profiles (HOME, PAGE, SITEMAP, DYNAMIC_OG, BADGE, STATIC_LONG, FEED, NO_STORE) and the 3-tier header rule.
  • references/loader-triage.md — decision matrix for splitting a loader between SSR-critical, prerender-safe, and client-fetch.
  • references/theme-ssr-recipe.md — next-themes + inline head script + cacheable /theme-vars.css compile-time recipe, incl. antd v6 cssVar override gotcha.

Workflow

text
[1]  Frame the migration as an edge-cache swap, not a framework swap
[2]  Stand up RR8 shell alongside legacy site (separate Vercel project)
[3]  Move src/app tree to RR8 route config; keep Next-like FS shape
[4]  Kill UA / geo / cookie-derived SSR variance
[5]  Split loader traffic: SSR-critical vs prerender-safe vs client-fetch
[6]  Restage theme SSR: next-themes + inline head script + /theme-vars.css
[7]  Rebuild middleware: Vercel Routing Middleware + root-loader mirror
[8]  Prerender the static surface (blog, about, docs) at build time
[9]  Decouple route-FS from feature-FS: routes/ = entry only
[10] Compile-time-ify runtime CSS via vite virtual modules
[11] Land 3-tier Cache-Control headers per route profile
[12] Cut traffic; leave the legacy Next site on for un-ported URL groups

Per-step notes

[1] Frame it as a cache swap. Before touching code, write down the per-locale RSC / ISR bill and the target cf-cache-status: HIT ratio. If the answer is "we cannot let CDN cache HTML because we personalise X", the migration will not pay — either fix X (move to CSR) or stop.

[3] Route FS shape. Do not flatten. Keep a Next-like nested tree (routes/blog/[slug]/page.tsx, routes/api/geo/route.ts, routes/docs/[...slugs]/page.tsx) even though RR8 uses explicit routes.ts. Every page module registers twice via a localized() helper: locale-less path (/blog/:slug, default en) and prefixed path (/:locale/blog/:slug). One module, two ids.

[4] Kill SSR variance. The single rule: SSR output must vary only by URL. No UA sniffing, no cookie-derived theme, no per-request geo. Move device detection to CSS media queries (or a matchMedia-based useIsMobile hook that agrees with those media queries), theme to next-themes + inline <head> script, geo to a client-side useGeo that calls /api/geo. If you leave one cookie-varying loader on a public route, that route stops caching.

[5] Loader triage. RR8 loaders re-run on client navigation as .data requests, which the CDN will not cache. Three buckets:

  • SSR-critical, prerender-safe (locale/route info, static blog metadata) → loader, and prerender at build.
  • SSR-critical, dynamic (fresh market/API data needed for first paint) → loader, but keep the SSR HTML cacheable by CDN because the URL fully identifies the result.
  • Post-hydration (marketplace lists, star counts, changelog tails) → strip from the loader; fetch client-side after hydration. This is the biggest CDN win — the .data round-trip disappears.

See references/loader-triage.md.

[6] Theme SSR. Ship both palettes (light + dark) as one cacheable stylesheet /theme-vars.css?v=<hash>, linked render-blocking from the root. An inline <head> script sets html[data-theme] from localStorage before first paint. antd v6 in cssVar mode re-declares --ant-* on any element carrying .ant-app / [class*='css-var-'], so scope the palette blocks to those selectors too, else the light literals shadow your dark palette on hydration. SSR CSS must be theme-agnostic: rewrite every appearance-dependent token to a var(--ant-*) reference so first paint picks the correct colour.

See references/theme-ssr-recipe.md.

[7] Middleware split. Legacy middleware.ts becomes two things:

  • src/middleware.ts (Vercel Routing Middleware, web-standard Request/Response, next()/rewrite() from @vercel/functions/middleware) — runs in prod before the CDN cache. Handles locale redirects, AI-tool redirects, NEXT_LOCALE cookie.
  • Root loader mirror — Vercel Routing Middleware does not run under bun run dev. Mirror the same locale / redirect logic in the root loader so dev matches prod.
  • Vercel's middleware compiler cannot resolve tsconfig path aliases. Pre-bundle src/middleware.ts (rolldown via vite's dep tree) into a self-contained /middleware.js in a build:middleware step.

[8] Prerender. RR8 supports build-time prerender. Ship the entire static surface (default-locale blog, docs, about, changelog) as HTML on disk; the CDN turns every one into a permanent HIT. Non-default locales stay dynamic if the bill allows; prerendering all 17 locales adds build minutes and repo weight.

[9] Route/feature FS. routes/ holds only route entry files (page.tsx, route.ts, Client.tsx, layout.tsx, [param] segments, not-found.tsx, pending-loading.tsx). Every feature implementation the route imports lives in src/features/<domain>/. Sub-features under [param] drop the brackets (coding/[agent] → features/coding/agent).

[10] Compile-time-ify runtime CSS. Any CSS generated in route.ts at request time (theme vars, antd static rules) becomes a vite virtual module baked at build. The route serves the module contents with a hash query and a long-lived Cache-Control. Zero runtime cost, infinite CDN cache.

[11] 3-tier Cache-Control. Every response ships three headers:

  • Cache-Control (browser)
  • Cloudflare-CDN-Cache-Control (Cloudflare)
  • Vercel-CDN-Cache-Control: no-store (bypass Vercel CDN — deliberate)

Because Cloudflare owns cache, Vercel CDN is a pass-through. Seven profiles (HOME, PAGE, SITEMAP, DYNAMIC_OG, BADGE, STATIC_LONG, FEED, NO_STORE) — see references/cache-control-profiles.md. Apply per route via export const headers = () => toHeaderMap(PAGE).

[12] Phased cut. Do not port every URL group at once. Leave privacy/terms, growth pages, im-landing, icon marketplace on the legacy Next site behind their existing URLs; port them one PR at a time using the frozen legacy repo as reference. The traffic split lives at the DNS / edge layer (see the sibling skill dokploy-traefik-traffic-split for the SPA-asset trap that breaks naive weighted splits).

Common pitfalls

MistakeFix
Framing the work as "Next → RR migration"It is a cache-frame swap. If Cloudflare cannot cache the resulting HTML, you gained nothing.
Any cookie / UA / geo header on the SSR response's VarySSR must vary only by URL. Move personalisation to CSR.
Cookie-derived theme surviving into loader logicCannot pre-paint from a cache-hit HTML. Ship both palettes in cacheable /theme-vars.css; use next-themes + inline <head> script; set data-theme from localStorage before hydration.
antd v6 cssVar mode shadowing your palette on hydrationantd re-declares --ant-* on every element carrying .ant-app / [class*='css-var-']. Scope palette blocks to those selectors too, and rewrite appearance-dependent SSR tokens to var(--ant-*).
Every loader keeps its Next data-fetch verbatimEvery retained loader becomes a .data round-trip on client nav. Triage: keep only SSR-critical; move the rest to client fetch.
Vercel-CDN-only stackVercel CDN cannot cache HTML that varies by cookie. Bring Cloudflare in front and set Vercel-CDN-Cache-Control: no-store.
Deleting middleware.ts before mirroring its logic in the root loaderDev has no Vercel Routing Middleware — locale redirects vanish, users hit 404. Mirror first, delete second.
tsconfig path alias in the middleware bundleVercel's middleware compiler cannot resolve aliases. Pre-bundle to a self-contained /middleware.js via rolldown before deploy.
Runtime CSS generation for theme vars / antd static rulesMove to a vite virtual module baked at build. Hash the URL, long-lived Cache-Control, infinite CDN cache.
Skipping prerender because "SSR is fast enough"Prerender is not about latency, it is about turning first-request MISS into permanent HIT. Blog / about / docs default locale must ship as HTML.
Flattening the route FSKeep a Next-like nested tree even under explicit routes.ts. It survives contributor rotation and matches URL 1:1.
Mixing feature code into routes/routes/ holds entry files only. All feature code lives in src/features/<domain>/.
Porting all 17 locale variants at prerender timeBuild minutes explode. Prerender default locale only; other locales dynamic.
One-shot cut over all URL groupsPhased cut — leave legacy Next site running for un-ported URL groups. Use the sibling skill for the traffic split.
Loader boundary shows no pending UI on client navRR8 does not render pending UI by default. Add a pending-loading.tsx skeleton per route segment (mirrors Next loading.tsx). Do not use antd Skeleton — the lobehub-ui variant differs.
Emoji-lookalike imports from @lobehub/ui where base-ui fitsPrefer @lobehub/ui/base-ui for headless primitives; keeps the SSR CSS smaller and avoids theme-token surprises.

Rules

  • SSR varies only by URL. No exceptions on public routes. If a variance is required (auth, session), that route is NO_STORE.
  • Skill first, cut second. Do not remove the legacy site until the new site's cf-cache-status HIT ratio matches the target.
  • Every route declares a Cache-Control profile. No implicit defaults; explicit headers export per route.
  • Middleware logic mirrors in the root loader. Two homes, one behaviour.

Verification

  • bun run build produces /middleware.js with no unresolved aliases (grep for @/ in the emitted bundle → zero hits).
  • bun run start serves the production build.
  • curl -I https://<host>/ twice: second response has cf-cache-status: HIT and vercel-cache: MISS (Vercel is pass-through by design).
  • No public route emits Set-Cookie in its SSR response.
  • curl -I https://<host>/blog/<slug>.data returns a body but is not cached at the CDN (cf-cache-status: BYPASS or MISS); that route was demoted to a client fetch instead if it appears on hot paths.
  • First paint shows the correct theme (light or dark) with no white → dark repaint. Test with prefers-color-scheme: dark and with theme=dark in localStorage.
  • NEXT_LOCALE=zh cookie on /blog/foo triggers 307 to /zh/blog/foo — both in dev (root-loader mirror) and prod (Vercel Routing Middleware).
  • build/client/blog/**/*.html exists for the prerendered default locale.
  • Every route module exports headers and each profile in references/cache-control-profiles.md appears at least once in the emitted route table.
  • Legacy site still serves the un-ported URL groups; traffic split config committed alongside the migration cut.

Tệp đi kèm

Khi kỹ năng đã được tải, mô hình có thể đọc các tệp này nếu cần. Các tệp này chỉ dùng để đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Nextjs Rsc To React Router V8 Migration làm được gì?

Dùng khi chuyển một website Next.js RSC / App-Router hỗ trợ nhiều locale sang React Router v8 để HTML do SSR tạo ra có thể được CDN lưu vào bộ nhớ đệm. Payload RSC không thể được lưu vào bộ nhớ đệm ở edge, còn số locale × số trang làm tăng chi phí. Bao gồm các bước theo thứ tự: loại bỏ biến thiên SSR theo UA/geo/cookie, tách loader `.data` khỏi các yêu cầu fetch phía client, thiết lập lại SSR cho theme (next-themes + script head + /theme-vars.css), tách middleware thành Vercel Routing Middleware + bản sao root loader, prerender nội dung tĩnh và thiết lập Cache-Control 3 tầng để Cloudflare q...

Vì sao nên dùng Nextjs Rsc To React Router V8 Migration trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Nextjs Rsc To React Router V8 Migration là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Nextjs Rsc To React Router V8 Migration trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/Innei/SKILL/tree/main/skills/infrastructure/nextjs-rsc-to-react-router-v8-migration. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm rồi cài đặt cả gói dưới dạng một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Nextjs Rsc To React Router V8 Migration?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Nextjs Rsc To React Router V8 Migration với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Nextjs Rsc To React Router V8 Migration với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Nextjs Rsc To React Router V8 Migration có miễn phí không?

Kỹ năng này được Innei phát hành trên GitHub. Hãy xem điều khoản giấy phép trong kho mã. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇