Skip to content

Begin react-router 5 → 6 migration via react-router-dom-v5-compat#381

Closed
blaipr wants to merge 2 commits into
ctrliq:mainfrom
blaipr:feature/react-router-v5-compat
Closed

Begin react-router 5 → 6 migration via react-router-dom-v5-compat#381
blaipr wants to merge 2 commits into
ctrliq:mainfrom
blaipr:feature/react-router-v5-compat

Conversation

@blaipr

@blaipr blaipr commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

📋 Merge instructions — all 13 open PRs, any order, zero conflicts

Every pair of open PRs has been verified conflict-free with git merge-tree (0 conflicts across all 78 pairs), and the union of all 13 was integration-tested green (Python suite 3477 passed, Jest 2873 passed, lint, build, licenses). Merge in any order you like. Two recommendations, not requirements:

The full queue:

  1. Merge PR Upgrade twisted, kubernetes, pyyaml, Cython and Django to latest allowed versions #374 - Upgrade twisted, kubernetes, pyyaml, Cython and Django to latest allowed versions
  2. Merge PR Upgrade django-oauth-toolkit 1.7.1 to 3.3.0 #376 - Upgrade django-oauth-toolkit 1.7.1 to 3.3.0
  3. Merge PR Upgrade styled-components from 5 to 6 #380 - Upgrade styled-components from 5 to 6
  4. Merge PR Begin react-router 5 → 6 migration via react-router-dom-v5-compat #381 - Begin react-router 5 → 6 migration via react-router-dom-v5-compat ⬅️ this PR
  5. Merge PR react-router migration batch 1: shared components, contexts and hooks #382 - react-router migration batch 1: shared components, contexts and hooks
  6. Merge PR react-router migration batch 2: screen directories (all except Inventory and Setting) #383 - react-router migration batch 2: screen directories (all except Inventory and Setting)
  7. Merge PR react-router migration batch 3: Inventory and Setting screens #384 - react-router migration batch 3: Inventory and Setting screens
  8. Merge PR Add React Testing Library migration infrastructure and first conversions #385 - Add React Testing Library migration infrastructure and first conversions
  9. Merge PR Remove EOL msrestazure, msrest and adal dependencies #386 - Remove EOL msrestazure, msrest and adal dependencies
  10. Merge PR Fix cross-test mock leak behind the flaky parallel test failures #388 - Fix cross-test mock leak behind the flaky parallel test failures
  11. Merge PR Build Activity Stream links for inventory source sync schedules #389 - Build Activity Stream links for inventory source sync schedules
  12. Merge PR Surface an error when the webhook credential type lookup returns nothing #390 - Surface an error when the webhook credential type lookup returns nothing
  13. Merge PR Modernize the frontend toolchain: Lingui 6, ESLint 9 and @dagrejs/dagre #391 - Modernize the frontend toolchain: Lingui 6, ESLint 9 and @dagrejs/dagre

SUMMARY

Stage 2 of the React stack modernization (stage 1 was #380). react-router-dom 6/7 removed Switch, useHistory, useRouteMatch, Redirect and withRouter — which 243 files in this codebase still use — so a big-bang upgrade isn't reviewable. This PR sets up React Router's official incremental-migration bridge and migrates the first screen:

  • react-router-dom-v5-compat added (ships router v6 alongside v5; works on React 17). CompatRouter is mounted inside the app's HashRouter, so v5 and v6 routing contexts coexist and components can migrate file by file.
  • Test harness support: testUtils/enzymeHelpers now renders a nested controlled v6 Router (location from the v5 context, navigator = the shared history object) inside the v5 Router. The v5 Router keeps the only history subscription, so there are no duplicate-subscription act() warnings, shallow rendering still works, and tests for migrated components get the v6 context automatically.
  • screens/Login migrated as the demonstration slice: <Redirect><Navigate> (compat package); the withRouter wrapper is dropped — the component never read the injected props.
  • Bonus test fix: Login.test.js contained a test.only dating to the initial import, which had silenced the other 14 Login tests ever since. It's removed, and the two assertions that rotted while dark are fixed (the custom login screen has no LoginMainHeader; branding-fetch errors fall back to the default logo without a modal). The suite now runs 2,869 tests — 14 more than before.

Migration recipe for follow-up PRs (per component, importing from react-router-dom-v5-compat)

v5 v6 compat
useHistory().push(x) const navigate = useNavigate(); navigate(x)
useRouteMatch().params useParams()
<Redirect to={x} /> <Navigate to={x} />
withRouter(C) hooks (or delete if the props are unused)

The root Switch in App.js migrates last; then react-router-dom flips to v6 and the compat package is removed.

Independent of #374, #376, #377, #378 and #380 — mergeable in any order. Same caveat as the other UI PRs: each regenerates package-lock.json, so later ones need a trivial npm install regen.

ISSUE TYPE

  • New or Enhanced Feature

COMPONENT NAME

  • UI

ASCENDER VERSION

awx: 25.4.1.dev5+gcda0899.d20260610

ADDITIONAL INFORMATION

All UI gates run against exactly this branch state (unmodified main + only this change):

npm --prefix awx/ui run lint     # clean
npm --prefix awx/ui run test     # 544 suites passed (1 skipped), 2869 tests passed (5 skipped)
npm --prefix awx/ui run build    # production build succeeds

Stage 2 of the React stack modernization. react-router-dom 6/7 removed
Switch, useHistory, useRouteMatch, Redirect and withRouter, which 243
files here still use, so the migration has to be incremental. This sets
up the official bridge and migrates the first screen:

- Add react-router-dom-v5-compat (ships router v6 alongside v5) and
  mount CompatRouter inside the app's HashRouter, so v5 and v6 routing
  contexts coexist and components can be migrated file by file.
- Wire the v6 context into testUtils/enzymeHelpers: the v5 Router keeps
  its history subscription and drives re-renders, while a fully
  controlled nested v6 Router (location from v5 context, navigator =
  the shared history) provides the v6 context without a second
  subscription - no act() warnings, and shallow rendering still works.
- Migrate screens/Login as the demonstration slice: Redirect becomes
  Navigate (from the compat package), and the withRouter wrapper is
  dropped (the component never used the injected props).
- Remove a test.only in Login.test.js that had silenced the other 14
  Login tests since the initial import, and fix the two assertions that
  had rotted while dark (the custom login screen has no LoginMainHeader;
  branding-fetch errors fall back to the default logo without a modal).
  The suite now runs 2869 tests, 14 more than before.

Migration recipe for follow-up PRs, per component:
  useHistory().push(x)  -> useNavigate(); navigate(x)
  useRouteMatch().params -> useParams()
  <Redirect to={x} />    -> <Navigate to={x} />
  withRouter(C)          -> hooks (or delete if props unused)
importing from 'react-router-dom-v5-compat'; the root Switch in App.js
migrates last, then react-router-dom flips to v6 and the compat package
is removed.
test_licenses requires every package.json dependency to have a matching
file in licenses/ui (caught by an integration run of the full Python
suite over all open PRs combined).
@blaipr

blaipr commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #392, which unifies the v5-compat bridge and all three migration batches into a single PR (one squashed commit, identical content, full gates green). Done as part of making the whole queue conflict-free and mergeable in any order.

@blaipr blaipr closed this Jun 11, 2026
@blaipr blaipr deleted the feature/react-router-v5-compat branch June 11, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant