Skip to content

Upgrade react-router-dom v6 to react-router v7 - #504

Merged
cigamit merged 2 commits into
ctrliq:mainfrom
blaipr:feature/react-router-v7
Jun 24, 2026
Merged

Upgrade react-router-dom v6 to react-router v7#504
cigamit merged 2 commits into
ctrliq:mainfrom
blaipr:feature/react-router-v7

Conversation

@blaipr

@blaipr blaipr commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

SUMMARY

Upgrade from react-router-dom 6.30.4 to react-router 7.18.0. In v7 the separate react-router-dom package was merged into react-router, so this is primarily a mechanical import rewrite.

What changed:

  • Replaced react-router-dom with react-router in package.json
  • Repointed all 271 source/test files from 'react-router-dom' to 'react-router'
  • Updated jest.mock('react-router-dom', ...) calls in 22 test files
  • Added a TextEncoder polyfill to the jest setup (react-router v7 references it at module load; jsdom doesn't provide it)
  • Updated the routerCompat module comment; retained the module itself as the canonical re-export site

No API changes — all hooks (useNavigate, useLocation, useParams, useMatch), components (Routes, Route, Link, Navigate, HashRouter, Router), and utilities (matchPath) are re-exported from react-router under the same names.

The history package (devDependency, used by the test harness's custom Router) is retained unchanged.

Depends on: #501

ISSUE TYPE

  • New or Enhanced Feature

COMPONENT NAME

UI

ASCENDER VERSION

awx: 25.4.1.dev126+gebb3790da5

ADDITIONAL INFORMATION

All 552 test suites pass (2908 tests). Lint clean.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR upgrades the UI routing layer from react-router-dom v6 to react-router v7 (where DOM exports are merged into react-router) and updates application/test imports accordingly. It also includes several React 18/test-harness adjustments that appear related to the prerequisite React upgrade referenced in #501.

Changes:

  • Replace react-router-dom with react-router across UI source and test files, including updated Jest mocks.
  • Update Jest environment setup to polyfill TextEncoder/TextDecoder and adjust console error handling.
  • Update UI entrypoint/tests for React 18 createRoot, and add guards/try-catches in workflow graph components to avoid jsdom/SVG-related failures.

Reviewed changes

Copilot reviewed 283 out of 284 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
awx/ui/package.json Switch routing dependency to react-router v7; includes React/testing-library version bumps and Jest TextEncoder setup file.
awx/ui/package-lock.json Lockfile updates reflecting react-router v7 and dependency upgrades.
awx/ui/src/routerCompat.js Re-export router symbols from react-router as the app’s canonical import site.
awx/ui/testUtils/rtlContexts.js Test harness router wrapper now imports <Router> from react-router.
awx/ui/config/jest/textEncoderPolyfill.js Adds TextEncoder/TextDecoder polyfill for the Jest/jsdom environment.
awx/ui/src/setupTests.js Console error filtering updated (now suppresses additional broad error markers).
awx/ui/src/index.js Uses React 18 createRoot and renders via root.render.
awx/ui/src/index.test.js Updates entrypoint test to mock/assert createRoot().render(...).
awx/ui/src/screens/User/UserTokenList/UserTokenList.test.js Updates router mocks (currently duplicates jest.mock('react-router', ...) in the same file).
awx/ui/src/screens/Setting/AzureAD/AzureADDetail/AzureADDetail.test.js Router mock updated but still mocks useRouteMatch while component uses useMatch.
awx/ui/src/screens/Job/WorkflowOutput/WorkflowOutputGraph.js Adds guards and wraps d3 zoom/fit initialization in try/catch to avoid environment-specific failures.
awx/ui/src/screens/Template/WorkflowJobTemplateVisualizer/VisualizerGraph.js Similar d3 zoom/fit try/catch changes and zoom event guard.
Files not reviewed (1)
  • awx/ui/package-lock.json: Generated file
Comments suppressed due to low confidence (2)

awx/ui/src/screens/User/UserTokenList/UserTokenList.test.js:25

  • There are two jest.mock('react-router', ...) declarations for the same module in this file. Jest will use the last mock factory, so the earlier mock (for useLocation) is effectively overwritten, which makes the test setup brittle and can lead to real useLocation leaking into the test unexpectedly.

Combine these into a single jest.mock that overrides both useLocation and useParams in one place.
awx/ui/src/screens/Setting/AzureAD/AzureADDetail/AzureADDetail.test.js:19

  • This mock overrides useRouteMatch, but the component now uses useMatch (see AzureADDetail.js). As written, the mock is dead code and can mislead future maintenance (and it won’t control the category param the component reads).

Mock useMatch (or set the router location via renderWithContexts) so the test setup reflects the actual routing API being used.

Comment thread awx/ui/src/index.js Outdated
Comment thread awx/ui/src/setupTests.js
Comment on lines +50 to +55
if (
!networkRequestUrl &&
!msg.includes('findDOMNode is deprecated') &&
!msg.includes('Uncaught [TypeError:') &&
!msg.includes('The above error occurred in')
) {
Comment thread awx/ui/src/screens/Job/WorkflowOutput/WorkflowOutputGraph.js
Comment thread awx/ui/src/screens/Job/WorkflowOutput/WorkflowOutputGraph.js
Comment on lines +208 to +212
try {
handleFitGraph();
} catch {
// d3 zoom/layout can fail in environments without full SVG support
}
Comment thread awx/ui/package.json
@blaipr
blaipr force-pushed the feature/react-router-v7 branch from 0b20052 to 289c657 Compare June 23, 2026 23:30
@blaipr

blaipr commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

All Copilot review comments addressed:

Inherited from #501 (fixed in commit c0af29f, picked up via rebase):

  • index.js detached div, VisualizerGraph/WorkflowOutputGraph try/catch gating, setupTests.js broad filters — all fixed per Upgrade React from 17 to 18 #501 comment.

Unique to this PR (fixed in commit 289c657):

  • UserTokenList.test.js (duplicate jest.mock): merged the two jest.mock('react-router') declarations into one so both useLocation and useParams are mocked in a single factory.
  • AzureADDetail.test.js (useRouteMatch vs useMatch): updated mock from useRouteMatch to useMatch to match the component's actual react-router v7 import.

The pnpm and PR-scope comments do not apply: this project uses npm, and this PR is intentionally stacked on #501.

@blaipr
blaipr force-pushed the feature/react-router-v7 branch from 289c657 to 218715e Compare June 24, 2026 08:22
@blaipr

blaipr commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main (includes PR #501 React 18 merge). Clean two commits, no conflicts. Ready to merge.

@cigamit

cigamit commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Just a quick merge conflict after merging the others, but otherwise this is good to go.

blaipr added 2 commits June 24, 2026 10:55
react-router v7 merges react-router-dom into the react-router package.
All imports are repointed from 'react-router-dom' to 'react-router'
(271 files), and jest.mock calls in 22 test files are updated to match.

A TextEncoder polyfill is added to the jest setup because react-router
v7's module initialization references TextEncoder, which jsdom does not
provide by default.

The routerCompat indirection module and the history package (used by
the test harness's custom Router) are retained unchanged.
- UserTokenList.test.js: merge duplicate jest.mock('react-router') into
  one declaration so both useLocation and useParams are mocked
- AzureADDetail.test.js: mock useMatch instead of useRouteMatch to match
  the component's actual import
@blaipr
blaipr force-pushed the feature/react-router-v7 branch from 218715e to e8b91f6 Compare June 24, 2026 08:55
@blaipr

blaipr commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main (includes PRs #501, #502, #503). No conflicts, ready to merge.

@cigamit
cigamit merged commit c09011a into ctrliq:main Jun 24, 2026
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.

3 participants