implement-rfc
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplement React Router RFC
实现 React Router RFC
Implement the RFC from the following GitHub discussion: $ARGUMENTS
基于以下GitHub讨论实现RFC:$ARGUMENTS
Branching
分支规范
RFC implementations should start from a clean working tree. If there are uncommitted changes, stop and ask me to resolve them before continuing.
- If you are already on a named branch that is at the same HEAD as , use that branch.
main - Otherwise, create a branch from using the format
main:{author}/rfc-{semantic-name}shgit branch {author}/rfc-{semantic-name} main git checkout {author}/rfc-{semantic-name}
RFC 实现应基于干净的工作树启动。如果存在未提交的更改,请停止并让我先解决这些更改再继续。
- 如果你当前所在的命名分支与 的 HEAD 一致,则使用该分支。
main - 否则,基于 创建分支,分支名格式为
main:{author}/rfc-{语义名称}shgit branch {author}/rfc-{semantic-name} main git checkout {author}/rfc-{semantic-name}
Workflow
工作流程
1. Fetch and Understand the RFC
1. 获取并理解RFC内容
Use to read the discussion URL. If a GitHub discussion number is given instead of a URL, construct:
WebFetchhttps://github.com/remix-run/react-router/discussions/<number>Extract:
-
Problem being solved: what pain point does this RFC address?
-
Proposed API: exact function signatures, hook names, types, option shapes
-
Affected modes: Declarative / Data / Framework / RSC Data / RSC Framework
-
Breaking changes: does this change or remove existing public API?
-
Open questions: anything explicitly marked as unresolved, "TBD", or asked as a question in the proposal
-
Status: are there linked tracking issues? Look for links to other github issues and read them to see if there is additional context.sh
gh issue view <number> --repo remix-run/react-router
使用 读取讨论链接。如果提供的是GitHub讨论编号而非链接,请拼接为:
WebFetchhttps://github.com/remix-run/react-router/discussions/<编号>提取以下信息:
-
要解决的问题:该RFC旨在解决什么痛点?
-
提案API:确切的函数签名、hook名称、类型、选项结构
-
受影响的模式:声明式 / 数据 / 框架 / RSC 数据 / RSC 框架
-
破坏性变更:是否修改或移除了现有的公共API?
-
待解决问题:提案中明确标记为未解决、“TBD”或作为问题提出的内容
-
状态:是否有相关的跟踪issue?查找指向其他GitHub issue的链接并阅读,确认是否有额外上下文。sh
gh issue view <number> --repo remix-run/react-router
2. Evaluate Community Feedback
2. 评估社区反馈
Fetch all comments from the discussion:
Use on and scroll through the full thread. Look for:
WebFetchhttps://github.com/remix-run/react-router/discussions/<number>- Concerns or objections raised by community members or maintainers
- Alternative proposals or API shape suggestions
- Edge cases raised that the proposal does not address
- Positive signals — repeated praise for a specific approach signals it's the right direction
- Maintainer responses — Ryan Florence, Michael Jackson, or other core team members clarifying intent
Summarize the community sentiment into:
- Points of consensus (safe to proceed)
- Points of contention (need resolution before implementing)
- Unanswered questions from the original proposal
获取讨论中的所有评论:
使用 访问 ,浏览完整讨论线程。重点关注:
WebFetchhttps://github.com/remix-run/react-router/discussions/<编号>- 社区成员或维护者提出的担忧或反对意见
- 替代方案或API结构建议
- 提案未覆盖的边界情况
- 积极信号——对某一方案的多次认可表明该方向是正确的
- 维护者回复——Ryan Florence、Michael Jackson或其他核心团队成员对意图的澄清
将社区反馈总结为以下几类:
- 共识点(可安全推进)
- 争议点(需在实现前解决)
- 原提案中未答复的问题
3. Resolve Outstanding Questions
3. 解决待处理问题
Before writing any code, present me with a numbered list of every unresolved question — from both the RFC itself and from community feedback. For each question:
- State the question clearly
- Summarize relevant community input
- Offer a recommended answer with reasoning
Ask me to confirm, override, or skip each question. Do not proceed to implementation until all questions are either answered or explicitly deferred.
Example format:
undefined在编写任何代码之前,请将所有未解决问题(包括RFC本身和社区反馈中的)以编号列表的形式呈现给我。每个问题需包含:
- 清晰陈述问题
- 总结相关的社区意见
- 给出推荐答案及理由
请让我对每个问题进行确认、驳回或跳过。在所有问题都得到答复或明确延期之前,不要进入实现阶段。
示例格式:
undefinedUnresolved Questions
Unresolved Questions
-
Shouldaccept a path argument for scoped matching? Community feedback: 3 comments in favor, 1 against (concerns about complexity). Recommendation: Yes — scoped matching improves type safety for nested routes. → Your decision: [confirm / override / defer]
useRouterState() -
What should happen when the path doesn't match the current location? Recommendation: Returnfor active state (consistent with
null). → Your decision: [confirm / override / defer]useMatch()
Save the resolved decisions to a scratch file at `tasks/rfc-decisions.md` for reference during implementation.-
Shouldaccept a path argument for scoped matching? Community feedback: 3 comments in favor, 1 against (concerns about complexity). Recommendation: Yes — scoped matching improves type safety for nested routes. → Your decision: [confirm / override / defer]
useRouterState() -
What should happen when the path doesn't match the current location? Recommendation: Returnfor active state (consistent with
null). → Your decision: [confirm / override / defer]useMatch()
将已确认的决策保存到临时文件 `tasks/rfc-decisions.md` 中,供实现阶段参考。4. Plan the Implementation
4. 制定实现计划
Before writing code, produce a concise implementation plan covering:
- New types/interfaces to add
- New functions/hooks to implement and their file locations
- Existing APIs to deprecate (mark with JSDoc + console warning in dev)
@deprecated - Whether a future flag is needed (see §5 below)
- Test files to create or extend (unit and/or integration)
- Changeset bump level (for new features,
minorfor breaking changes behind a future flag that is now defaulted on)major
Present the plan to me and wait for approval before implementing.
在编写代码之前,制定一份简洁的实现计划,涵盖以下内容:
- 需新增的类型/接口
- 需实现的新函数/hook及其文件位置
- 需弃用的现有API(标记 JSDoc + 开发环境下的控制台警告)
@deprecated - 是否需要未来特性标志(见下文第5节)
- 需创建或扩展的测试文件(单元和/或集成测试)
- 变更集版本升级级别(新功能为 ,未来特性标志默认开启的破坏性变更为
minor)major
将计划提交给我,等待批准后再开始实现。
5. Future Flags for Breaking Changes
5. 破坏性变更的未来特性标志
If the RFC changes or removes existing public API behavior, it must ship behind a future flag which will start with an prefix.
unstable_Future flag pattern:
-
Add the flag toin
FutureConfig:packages/react-router/lib/router/utils.tstsexport interface FutureConfig { // existing flags... unstable_myNewBehavior: boolean; } -
Gate the new behavior on the flag:ts
if (router.future.unstable_myNewBehavior) { // new behavior } else { // legacy behavior } -
Document the flag inif it exists.
docs/upgrading/future-flags.md
New additive APIs (no behavior change to existing code) do not need a future flag.
如果RFC修改或移除了现有公共API的行为,必须通过以 为前缀的未来特性标志发布。
unstable_未来特性标志模式:
-
将标志添加到的
packages/react-router/lib/router/utils.ts中:FutureConfigtsexport interface FutureConfig { // existing flags... unstable_myNewBehavior: boolean; } -
通过标志控制新行为的启用:ts
if (router.future.unstable_myNewBehavior) { // new behavior } else { // legacy behavior } -
如果存在,在其中记录该标志。
docs/upgrading/future-flags.md
新增的增量API(不改变现有代码的行为)不需要未来特性标志。
6. Key File Locations
6. 关键文件位置
| Area | Files |
|---|---|
| Core router logic | |
| Router types/utils | |
| React components | |
| React hooks | |
| Public exports | |
| DOM utilities | |
| Framework/Vite plugin | |
| RSC runtime | |
| Unit tests | |
| Integration tests | |
| Future flags doc | |
Confirm existing patterns before writing new code - prefer using the LSP but / also work. Match naming conventions and code style exactly.
GrepGlob| 领域 | 文件路径 |
|---|---|
| 核心路由逻辑 | |
| 路由类型/工具函数 | |
| React 组件 | |
| React hooks | |
| 公共导出 | |
| DOM 工具函数 | |
| 框架/Vite 插件 | |
| RSC 运行时 | |
| 单元测试 | |
| 集成测试 | |
| 未来特性标志文档 | |
在编写新代码之前确认现有模式——优先使用LSP,也可以用 /。严格遵循命名规范和代码风格。
GrepGlob7. Implement the Feature
7. 实现功能
Follow the approved plan. For each logical unit of work:
- Write the implementation
- Export from the appropriate public entry point ()
packages/react-router/index.ts - Add JSDoc to any APIs being superseded
@deprecated - Run typecheck to catch type errors early:
sh
pnpm typecheck
Keep changes minimal and focused. Do not refactor unrelated code. Commit as often as needed.
遵循已批准的计划。每个逻辑工作单元:
- 编写实现代码
- 在对应的公共入口文件()中导出
packages/react-router/index.ts - 为所有被取代的API添加 JSDoc 标记
@deprecated - 运行类型检查,尽早发现类型错误:
sh
pnpm typecheck
保持变更的最小化和聚焦性。不要重构不相关的代码。根据需要频繁提交。
8. Write Tests
8. 编写测试
Unit tests (for hooks, pure router logic, component behavior — no build):
- Location:
packages/react-router/__tests__/ - Runner: Jest →
pnpm test packages/react-router/__tests__/<file> - Cover: happy path, edge cases identified in RFC/community feedback, future flag gating (if applicable), deprecation warnings
Integration tests (for Vite/Framework Mode, SSR, hydration):
- Location:
integration/ - Runner: Playwright →
pnpm test:integration:run --project chromium integration/<file> - Required if the RFC touches Framework Mode, file-system routing, or SSR behavior
Run all tests and confirm they pass:
sh
pnpm test packages/react-router/
pnpm test:integration:run --project chromium # only if integration tests were added/changed单元测试(用于hook、纯路由逻辑、组件行为——无需构建):
- 位置:
packages/react-router/__tests__/ - 运行器:Jest →
pnpm test packages/react-router/__tests__/<文件> - 覆盖范围:正常路径、RFC/社区反馈中提到的边界情况、未来特性标志控制(如适用)、弃用警告
集成测试(用于Vite/框架模式、SSR、水合):
- 位置:
integration/ - 运行器:Playwright →
pnpm test:integration:run --project chromium integration/<文件> - 如果RFC涉及框架模式、文件系统路由或SSR行为,则必须编写集成测试
运行所有测试并确认通过:
sh
pnpm test packages/react-router/
pnpm test:integration:run --project chromium # only if integration tests were added/changed9. Lint and Typecheck
9. 代码检查与类型校验
sh
pnpm lint
pnpm typecheckFix all errors before proceeding.
sh
pnpm lint
pnpm typecheck修复所有错误后再继续。
10. Create a Change File
10. 创建变更文件
Create . Use the RFC title or tracking issue as the description:
packages/<package>/.changes/<bump-level>.<descriptive-name>.mdmarkdown
feat: <brief description matching the RFC title>
Implements the `useRouterState()` RFC (#12358). Deprecates `useLocation`,
`useParams`, `useSearchParams`, `useNavigation`, `useMatches`, `useMatch`,
`useNavigationType`, and `useViewTransitionState` in favor of a unified API.
Enable the `unstable_consolidatedRouterState` future flag to opt in.Bump levels:
- — bug-adjacent fix only
patch - — new additive API (no breaking changes)
minor - — breaking change (should be rare; most breaking changes go behind a future flag as
majorfirst)minor - — new API that is not yet stable (e.g. added in a future flag, or an experimental API that may be removed without a major bump)
unstable
创建 。使用RFC标题或跟踪issue作为描述:
packages/<包名>/.changes/<升级级别>.<描述性名称>.mdmarkdown
feat: <brief description matching the RFC title>
Implements the `useRouterState()` RFC (#12358). Deprecates `useLocation`,
`useParams`, `useSearchParams`, `useNavigation`, `useMatches`, `useMatch`,
`useNavigationType`, and `useViewTransitionState` in favor of a unified API.
Enable the `unstable_consolidatedRouterState` future flag to opt in.版本升级级别:
- — 仅类似bug修复的变更
patch - — 新增增量API(无破坏性变更)
minor - — 破坏性变更(应很少见;大多数破坏性变更会先通过未来特性标志以
major版本发布)minor - — 尚未稳定的新API(例如通过未来特性标志添加的API,或可能在不升级major版本的情况下移除的实验性API)
unstable
11. Report and Review
11. 汇报与评审
Summarize:
- What RFC was implemented and which decisions were made
- New public APIs added (with brief usage example)
- APIs deprecated and the migration path
- Future flag name (if applicable) and how to opt in
- Test coverage added
- Anything deferred or explicitly out of scope
Ask me to review and iterate before opening a PR.
总结以下内容:
- 实现了哪个RFC,做出了哪些决策
- 新增的公共API(附简要使用示例)
- 被弃用的API及迁移路径
- 未来特性标志名称(如适用)及开启方式
- 新增的测试覆盖
- 所有延期或明确超出范围的内容
在创建PR之前,请让我进行评审和迭代。
12. Commit
12. 提交代码
Once I approve, commit and open a PR to :
mainsh
gh pr create --base main --title "feat: <RFC title>" --body "..."PR body should include:
- Link to the RFC discussion (Closes or Implements #NNNN)
- Summary of what was implemented
- Future flag instructions if applicable
- Testing notes
- Any decisions that deviated from the original proposal and why
一旦我批准,提交代码并向 分支创建PR:
mainsh
gh pr create --base main --title "feat: <RFC title>" --body "..."PR正文应包含:
- RFC讨论的链接(Closes 或 Implements #NNNN)
- 实现内容的总结
- 未来特性标志的使用说明(如适用)
- 测试说明
- 所有偏离原提案的决策及其原因