360 Secure SkillHub
360 安全技能中心

migrate-react-spectrum-v3-to-s2

按八个步骤把 React Spectrum v3(S1)项目升级到 S2:检查包清单与构建工具、安装 @react-spectrum/s2、先 dry-run 再执行 s1-to-s2 codemod、格式化改动文件、修复 TODO(S2-upgrade) 注释、运行类型检查、测试与构建验证,最后输出迁移报告和后续建议。不包含 React 等大版本升级。

分类:开发
未知作者
热度 0.00
最近更新 2026-11-12 11:44:05

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add react-spectrum.adobe.com/migrate-react-spectrum-v3-to-s2
兼容性
通用兼容
联网要求
需要联网
数据出网
数据不出本机
Metadata
name
migrate-react-spectrum-v3-to-s2
description
Upgrade React Spectrum v3 (Spectrum 1) codebases to React Spectrum S2. Use when developers mention migrating or upgrading from React Spectrum v3, Spectrum 1, S1, @adobe/react-spectrum, @react-spectrum/* packages, or codemod-assisted upgrades to @react-spectrum/s2.
license
Apache-2.0
compatibility
Requires a React project currently using React Spectrum v3, @react-spectrum/* packages, or related React Spectrum v3 helpers.
metadata
{"author":"Adobe","website":"https://react-spectrum.adobe.com/"}

React Spectrum v3 to S2 migration

Upgrade React Spectrum v3 codebases to S2 by following these eight steps in order.

Scope

This skill covers only the React Spectrum v3 (S1) to S2 migration. Do not perform major dependency upgrades such as React version bumps (e.g. React 16→17, 17→18, 18→19) as part of this migration. If the project needs a major dependency upgrade, note it as a recommended follow-up in the final report (Step 8) rather than attempting it during migration.

Step 1: Inspect the codebase

  • Search package manifests for @adobe/react-spectrum, @react-spectrum/*, and @spectrum-icons/*.
  • Note the package manager (npm, yarn, pnpm) from the lockfile.
  • Identify the bundler used by the migration target (Parcel, Vite, webpack, Next.js, Rollup, ESBuild).
  • In monorepos, inspect the specific package or app being migrated rather than the workspace root.
  • Find app entrypoints, root providers, shared test wrappers, toast setup, and any defaultTheme usage.

See Prerequisites for the full inspection checklist and minimum tool versions.

Step 2: Install @react-spectrum/s2

Install the S2 package with the project's package manager:

npm install @react-spectrum/s2
yarn add @react-spectrum/s2
pnpm add @react-spectrum/s2

If the bundler is not Parcel v2.12.0+, also install and configure unplugin-parcel-macros as a dev dependency. See Getting started for bundler-specific setup instructions.

Step 3: Dry-run the codemod

Preview what the codemod will change before applying:

npx @react-spectrum/codemods s1-to-s2 --agent --dry
yarn dlx @react-spectrum/codemods s1-to-s2 --agent --dry
pnpm dlx @react-spectrum/codemods s1-to-s2 --agent --dry

Use npx for npm/Yarn 1, yarn dlx for Yarn Berry/PnP, pnpm dlx for pnpm. Add --path <dir> for monorepos or partial rollouts. Add --components A,B only when explicitly requested for incremental migration.

Review the dry-run output to understand the scope of changes.

Step 4: Run the codemod

Execute the codemod to transform the source files:

npx @react-spectrum/codemods s1-to-s2 --agent
yarn dlx @react-spectrum/codemods s1-to-s2 --agent
pnpm dlx @react-spectrum/codemods s1-to-s2 --agent

Use the same --path and --components flags as the dry run if applicable.

Step 5: Format with the project's formatter

If the project has a formatter (Prettier, ESLint, Biome, Oxfmt, etc.), run it on the changed files to remove extraneous formatting changes introduced by the codemod.

Step 6: Fix remaining TODO(S2-upgrade) comments

Search the codebase for TODO(S2-upgrade) comments left by the codemod. Each one marks a change that requires manual review.

See Focused manual fixes for information on how to fix these.

Also reference the react-spectrum-s2 skill (if available) for full S2 component documentation when needed.

Step 7: Validate

Run the project's own toolchain to verify the migration is complete:

  1. Install dependencies if package manifests changed.
  2. Run the typecheck or compile step (e.g. tsc --noEmit, tsc -b).
  3. Run tests covering the migrated code. Prefer the narrowest test scope that covers the changed files.
  4. Run the build to confirm the output is intact.

In monorepos, validate the affected package first with its own scripts before running workspace-wide checks. Fix any failures before declaring the migration complete.

Step 8: Generate final report

After the migration is complete, produce a final report for the user with the following sections:

Summary of changes

  • Packages added and removed.
  • What the codemod changed (files affected, components migrated).
  • Manual fixes applied (layout components, icons, dialogs, collections, toast, etc.).

Remaining issues

  • Any unresolved TODO(S2-upgrade) comments.
  • Type errors, test failures, or known gaps that still need attention.

Recommended follow-ups

Deep reference

Use these when you need more component-by-component or API-level detail:

  • Migration guide: comprehensive component-by-component migration reference.
  • Getting started: framework setup and macro configuration.
  • Provider: locale, router, color-scheme, and SSR usage.
  • Styling: style macro overview including runtime conditions, CSS variables, CSS optimization, and CSS resets.
  • Style macro: exact style macro syntax and constraints.
  • Toast: full S2 toast API and examples.