Repository navigation
Description
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 #11719 and #12201 (comment)).
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-configand@types/history. Today,@docusaurus/types,@docusaurus/module-type-aliases,@docusaurus/theme-commonand@docusaurus/plugin-content-docspublish them asdependencies. - ESM-only output with an
exportsmap.@docusaurus/corerequires Node>=26.13, so the broken links checker can stillrequire()it. - Zero runtime dependencies, with
reactas 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
createContextpolyfill (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
- Vendor the code as-is in a new package and switch
@docusaurus/coreto it, with no behavior change (tests, website build diff, Argos). - Remove the dependencies, the unused APIs and the legacy code, and publish ESM only.
- Convert to TypeScript with built-in types, port the upstream v5 test suites, and remove the
@types/*dependencies. - Later, modernize the implementation. For example,
Routersubscribes tohistoryin its constructor, which is unsafe with StrictMode and concurrent rendering:useSyncExternalStorewould 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-domandreact-router-configto 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/coreand only exposed through@docusaurus/router? Do we expose more APIs there (likeStaticRouter/MemoryRouterfor tests)? - Do we keep the
HistoryandLocationtypes compatible with@types/history4, so code typed against it keeps compiling? - Is the 4th step (hooks,
useSyncExternalStore) in scope for 5.0?
(AI-assisted)
Activity