Fork and modernize React Router v5 for our own usage

オープン
#13,080 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発

調査の方向性

Start by reading the current React Router v5 packages and Docusaurus routing entry points; the issue names no specific files or tests. The proposed first step is to vendor the packages and switch @docusaurus/core with no behavior change, checking tests, the website build diff, and Argos. Completion spans removing unused APIs and dependencies, adding TypeScript types, and verifying compatibility with the listed Docusaurus and plugin APIs.

索引モデルが issue の本文から書いたものです。

説明

domain: dependencies proposal

Motivation

Docusaurus runs on React Router v5 (react-router and react-router-dom 5.3.4, react-router-config 5.1.1, history 4.10.1), and we plan to stay on it: upgrading is too disruptive for our ecosystem and would increase the weight of a Docusaurus site (see https://github.com/meta/docusaurus/issues/11719 and https://github.com/meta/docusaurus/pull/12201#issuecomment-6504253771).

But v5 is frozen: its last release is 5.3.4 from October 2022, and React Router's security policy lists "6.x and below" as unsupported. It also carries a lot of legacy we don't need: Browserify transforms, a createContext polyfill for React < 16.3, propTypes, Babel helpers, CommonJS-first builds and community types from DefinitelyTyped.

We'd like to fork it in the monorepo, clean it up and modernize it for our own usage, and remove the parts we don't need.

No known v5 vulnerability

This is not a security fix. As of November 2026, no published advisory affects React Router v5 code:

  • The React Router security advisories (about 30, up to November 18, 2026) all target 6.x, 7.x or 8.x. Most are about data/framework mode, SSR, single fetch and RSC, which don't exist in v5.
  • The GitHub Advisory Database and OSV return no advisory for the exact versions we install.

The transitive dependencies are clean too:

Package Version Advisories
path-to-regexp 1.9.0 CVE-2024-45296 (ReDoS) affects <1.9.0, fixed in the version we install. The 2026 CVEs only affect 0.1.x and 8.x
@babel/runtime 7.29.7 CVE-2025-27789 affects <7.26.10, fixed in the version we install
history, resolve-pathname, value-equal, hoist-non-react-statics, prop-types, object-assign, react-is, loose-envify, js-tokens, tiny-invariant, tiny-warning, isarray None, ever

The risk is about the future: if a v5 vulnerability is found, nobody will publish a fix. Owning the code means we can.

What we use

Official packages
Package APIs
react-router-dom BrowserRouter, HashRouter (future.experimental_router: 'hash'), StaticRouter (SSR), Route (PendingNavigation), Link, NavLink (@docusaurus/Link), Redirect, matchPath, useHistory, useLocation. MemoryRouter in tests only
react-router-config matchRoutes (client and the broken links checker), renderRoutes
history Types (Location, History, Action) and the history object: push, replace, listen, block, location

Our public API re-exports a subset: @docusaurus/router exports useHistory, useLocation, Redirect and matchPath, @docusaurus/Link wraps Link/NavLink, and @docusaurus/renderRoutes re-exports renderRoutes. The Location type of history is part of @docusaurus/types (onRouteUpdate).

Third-party plugins

I checked the latest release of the 20 most downloaded third-party plugins and themes (by npm weekly downloads). None imports react-router, react-router-dom, react-router-config or history directly, and none declares them as a dependency. The 6 that do routing all use @docusaurus/router:

Plugin Weekly downloads Usage
@easyops-cn/docusaurus-search-local 562k useHistory, useLocation: push, replace, reads pathname/search/hash
docusaurus-theme-openapi-docs 149k useHistory: listen, location, replace
docusaurus-lunr-search 117k useHistory, useLocation: push(url, state) and location.state
@cmfcmf/docusaurus-search-local 45k useHistory, useLocation: push(url, state) and location.state
docusaurus-theme-search-typesense 17k useHistory, useLocation: push, replace, reads search
@conduction/docusaurus-preset 7.7k useLocation: reads pathname

The other 14 have no routing code: docusaurus-plugin-sass, docusaurus-plugin-openapi-docs, docusaurus-plugin-image-zoom, docusaurus-theme-redoc, redocusaurus, docusaurus-plugin-redoc, docusaurus-plugin-typedoc, docusaurus-plugin-llms, @signalwire/docusaurus-plugin-llms-txt, @scalar/docusaurus, @graphql-markdown/docusaurus, @r74tech/docusaurus-plugin-panzoom, docusaurus-plugin-mcp-server, docusaurus-plugin-copy-page-button. The ones that render links use @docusaurus/Link with string to values only.

The only feature they use that official packages don't is the location state: two search plugins pass the search terms to highlight through history.push(url, state), then read and clear location.state. The fork must keep it.

What we don't use

Nothing in the official packages or these 20 plugins uses withRouter, Prompt, useParams, useRouteMatch, generatePath, Router, Switch (only used internally by renderRoutes), or the __RouterContext/__HistoryContext internals. These are candidates for removal.

Proposal

Fork the 4 packages into a single monorepo package (for example @docusaurus/react-router, available on npm) that only @docusaurus/core depends on, with:

  • TypeScript source and built-in types, replacing @types/react-router-dom, @types/react-router-config and @types/history. Today, @docusaurus/types, @docusaurus/module-type-aliases, @docusaurus/theme-common and @docusaurus/plugin-content-docs publish them as dependencies.
  • ESM-only output with an exports map. @docusaurus/core requires Node >=26.13, so the broken links checker can still require() it.
  • Zero runtime dependencies, with react as a peer:
Dependency Plan
prop-types, object-assign, react-is Remove: React 19 ignores propTypes
loose-envify, js-tokens Remove: only a Browserify transform ("browserify": {"transform": ["loose-envify"]}), never run by webpack/Rspack
@babel/runtime Remove: compile for modern JS, no helpers
tiny-invariant, tiny-warning Inline (about 35 lines)
hoist-non-react-statics Remove with withRouter
history 4, resolve-pathname, value-equal Vendor, keeping the location state and block/listen
path-to-regexp 1.9.0 Vendor the 2 functions used by matchPath (a rewrite risks changing how plugin route paths match)
  • Only the APIs we use: remove the unused ones listed above, the createContext polyfill (miniCreateReactContext, 175 lines) and the deprecated CommonJS entry points.

The codebase is small: about 1,030 lines for react-router, 380 for react-router-dom, 55 for react-router-config, 920 for history, plus about 700 lines of community types. Most of the work is in the types and the verification, not in the code.

Possible steps
  1. Vendor the code as-is in a new package and switch @docusaurus/core to it, with no behavior change (tests, website build diff, Argos).
  2. Remove the dependencies, the unused APIs and the legacy code, and publish ESM only.
  3. Convert to TypeScript with built-in types, port the upstream v5 test suites, and remove the @types/* dependencies.
  4. Later, modernize the implementation. For example, Router subscribes to history in its constructor, which is unsafe with StrictMode and concurrent rendering: useSyncExternalStore would fit better.

Breaking changes

Docusaurus would no longer install react-router, react-router-dom, react-router-config and history. Sites, swizzled components and plugins that import them directly today work only because they resolve the same copy as @docusaurus/core:

  • Code relying on hoisting would fail to resolve these packages.
  • Code installing its own copy would get a separate router context, so useLocation() would crash at runtime.

They should use @docusaurus/router instead. The top 20 plugins already do, but we can't measure custom site code from npm.

Open questions

  • Should we alias react-router, react-router-dom and react-router-config to the fork in the bundler config? Missing exports would then fail at build time with a clear error instead of crashing at runtime, but we'd have to keep their module names around.
  • Public package, or internal to @docusaurus/core and only exposed through @docusaurus/router? Do we expose more APIs there (like StaticRouter/MemoryRouter for tests)?
  • Do we keep the History and Location types compatible with @types/history 4, so code typed against it keeps compiling?
  • Is the 4th step (hooks, useSyncExternalStore) in scope for 5.0?

(AI-assisted)

主要言語
TypeScript
スター
66.6k
フォーク
10.1k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

facebook/docusaurus のほかの issue

facebook/docusaurus の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。