E536 Upgrade react-router-dom to v6 by raza-khan0108 · Pull Request #14974 · linkerd/linkerd2 · GitHub
[go: up one dir, main page]

Skip to content

Upgrade react-router-dom to v6#14974

Open
raza-khan0108 wants to merge 2 commits intolinkerd:mainfrom
raza-khan0108:react-router-v6-upgrade
Open

Upgrade react-router-dom to v6#14974
raza-khan0108 wants to merge 2 commits intolinkerd:mainfrom
raza-khan0108:react-router-v6-upgrade

Conversation

@raza-khan0108
Copy link

Summary

This PR upgrades react-router-dom from v5 to v6 in the dashboard web app (#7252).

Upgrading to React Router v6 introduces many breaking changes (like the removal of <Switch>, <Redirect>, and the withRouter HOC, as well as breaking changes to props inside <Route> components). To minimize churn in the codebase and keep the transition clean for legacy components, we have implemented a backward-compatible HOC (withRouter.jsx) that wraps v6 hooks (useNavigate, useLocation and useParams) and translates them into the history, location and match props that the existing components expect.

Changes Made

  • Package Updates:
    • Upgraded react-router-dom to ^6.22.3.
    • Updated use-query-params to ^3.2.1 to support the new ReactRouter6Adapter.
    • Removed deprecated dependencies (history and react-router-prop-types).
  • Routing Implementation (web/app/js/index.js):
    • Replaced <Switch> with <Routes>.
    • Converted <Redirect> to <Navigate replace>.
    • Swapped the render prop in <Route> for the element prop.
  • Compatibility Layer (web/app/js/components/util/withRouter.jsx):
    • Created a custom withRouter high-order component. This bridges v6 hooks into legacy v5 props so the existing class components (like NavigationBase) do not need heavy refactoring.
  • Tests Refactored:
    • Updated testHelpers.jsx and individual component test suites (Navigation.test.jsx, BreadcrumbHeader.test.jsx) to use MemoryRouter with initialEntries instead of deprecated custom contexts built from createMemoryHistory.

Testing

  • Automated Tests: yarn test was run directly. All 15 suites (95 tests) pass successfully, restoring the complete test coverage.
  • Local Validation: Tested dashboard navigation across multiple namespaces manually. Ensured route transitions, redirects (e.g., from / to /namespaces), and parameter extractions worked seamlessly.

@raza-khan0108 raza-khan0108 requested a review from a team as a code owner February 28, 2026 18:49
Copy link
@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dc0a14f39b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +125 to +126
<QueryParamProvider adapter={ReactRouter6Adapter}>
<Routes>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Badge Import React Router v6 symbols before using them

This JSX now references ReactRouter6Adapter, Routes, and Navigate, but index.js still imports ReactRouter5Adapter and does not import the new router components; as written, rendering AppHTML will hit a ReferenceError and prevent the dashboard from loading at all. Please update the imports in this file to match the new identifiers used in the routing tree.

Useful? React with 👍 / 👎.

replace: (path, state) => navigate(path, { replace: true, state }),
location,
}}
match={{ params }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Populate full match object in withRouter shim

The compatibility wrapper only passes match={{ params }}, but legacy components still rely on match.url; for example ResourceDetail calls match.url.match(...) in getResourceFromUrl and compares prevProps.match.url in componentDidUpdate, so navigating to resource detail routes will throw once match.url is missing. The shim needs to provide a v5-compatible match shape (at least including url) to avoid breaking these pages.

Useful? React with 👍 / 👎.

@raza-khan0108
Copy link
Author

React Router v6 Upgrade Updates

Added a few specific corrections to ensure the dashboard reliably functions after the react-router-dom v6 upgrade:

  • Corrected Imports: Removed legacy bindings (ReactRouter5Adapter, Switch, Redirect) and imported ReactRouter6Adapter, Routes, and Navigate into /web/app/js/index.js, fixing ReferenceError crashes during local load.
  • Enhanced compatibility shim: Updated withRouter to pass match.url by inferring it from location.pathname, which enables legacy component routing components (like ResourceDetail) to function unmodified when relying on matching behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0