Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: React router dom from v5 to v6 #2580

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

Zen-cronic
Copy link
Contributor

@Zen-cronic Zen-cronic commented Jan 10, 2025

Which problem is this PR solving?

Description of the changes

How was this change tested?

  • npm run test

Commands Ran

Checklist

Copy link

codecov bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.58%. Comparing base (1ee19c2) to head (4228454).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2580      +/-   ##
==========================================
- Coverage   96.58%   96.58%   -0.01%     
==========================================
  Files         255      255              
  Lines        7732     7728       -4     
  Branches     1944     1996      +52     
==========================================
- Hits         7468     7464       -4     
  Misses        264      264              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Zen-cronic
Copy link
Contributor Author

Zen-cronic commented Jan 13, 2025

Migration to v6 done! All the unit tests pass

TODOs:

  • fix error on "Compare" page (TraceDiff):
    Error: HTTP Error: strconv.ParseUint: parsing "...": invalid syntax
    URL: /api/traces/...
    Response body: { "data": null, "total": 0, "limit": 0, "offset": 0, "errors": [ { "code": 400, "msg": "strconv.ParseUint: parsing \"...\": invalid syntax" } ] }

Or when two traces are selected:
Error: HTTP Error: TraceID cannot be longer than 32 hex characters: 9a344d0e849454d3c184becc70ea8d1d...28eba2ae54dcf6b5cb1f9541926bc7ab
URL: /api/traces/9a344d0e849454d3c184becc70ea8d1d...28eba2ae54dcf6b5cb1f9541926bc7ab
Response body: Response body { "data": null, "total": 0, "limit": 0, "offset": 0, "errors": [ { "code": 400, "msg": "TraceID cannot be longer than 32 hex characters: 9a344d0e849454d3c184becc70ea8d1d...28eba2ae54dcf6b5cb1f9541926bc7ab" } ]

Interestingly, manually going to http://localhost:5173/trace/ does not throw; it shows the expected ui component.

Problem found: react-router dropped regex path support in v6

  • Continue v7 migration Separate PR

@yurishkuro
Copy link
Member

please do not bundle 6 & 7 migration into one PR, let's get a green CI and merge

@yurishkuro
Copy link
Member

please document in the description how the dependency files were changed (which commands did you run). For example, why are "peer": true entries being removed? Are you using a different version of npm?

Signed-off-by: Kaung Zin Hein <[email protected]>
@@ -29,9 +29,9 @@ describe('<TraceIDSearchInput />', () => {
history = createMemoryHistory();
render(
<HistoryProvider history={history}>
Copy link
Member

Choose a reason for hiding this comment

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

why in packages/jaeger-ui/src/components/App/index.jsx the history provider is removed but here it's not? What is the motivation for either decision?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In packages/jaeger-ui/src/components/App/index.jsx, HistoryProvider is removed b/c rrd v6 works without being wrapped with that component.

But in this test and other tests, the history object from it's namesake package is used for assertions. So, removing HistoryProvider would mean a rewrite for these tests.

Copy link
Member

Choose a reason for hiding this comment

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

but what's the story with the history package, aren't we going to have to remove it altogether as incompatible going forward? It's ok if that clean-up can be done incrementally, we can defer it to other PRs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

history is no longer a peer dep in v6 and later. And yes, we should have a separate PR for removing it from this repo.

And we need to consider how to replace the function of that package - currently, it's used to provide the navigation props (e.g., history.push(/)) in class-based components wrapped with withRouteProps. Because they're class based, we can't use hooks like useNavigation). This discussion is better continued in another PR :)

Copy link
Member

Choose a reason for hiding this comment

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

Specifically, the migration guide you linked recommends using navigate instead of history.

Copy link
Member

Choose a reason for hiding this comment

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

And the docs say BrowserRouter incorporates the history in it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Specifically, the migration guide you linked recommends using navigate instead of history.

yep, we should replace history with navigate from the useNavigate hook. But that change can't be made unless the class-based components (like this) are rewritten into functional components.

@Zen-cronic
Copy link
Contributor Author

please document in the description how the dependency files were changed (which commands did you run). For example, why are "peer": true entries being removed? Are you using a different version of npm?

noted. i'm on node v22.12.0 and npm 10.9.0.
The peer:true entries seem to be related to theantd library

Signed-off-by: Kaung Zin Hein <[email protected]>
@Zen-cronic Zen-cronic changed the title Update: react router dom from v5 to v7 Update: react router dom from v5 to v6 Jan 13, 2025
@Zen-cronic Zen-cronic changed the title Update: react router dom from v5 to v6 Update: React router dom from v5 to v6 Jan 13, 2025
Signed-off-by: Kaung Zin Hein <[email protected]>
@yurishkuro yurishkuro added changelog:bugfix-or-minor-feature 🐞 Bug fixes, Minor Improvements changelog:dependencies Update to dependencies and removed changelog:bugfix-or-minor-feature 🐞 Bug fixes, Minor Improvements labels Jan 13, 2025
@Zen-cronic Zen-cronic marked this pull request as ready for review January 13, 2025 23:18
@Zen-cronic Zen-cronic requested a review from a team as a code owner January 13, 2025 23:18
@Zen-cronic Zen-cronic requested review from pavolloffay and removed request for a team January 13, 2025 23:18
<Routes>
<Route path="/" element={<Page />}>
<Route index element={<SearchTracePage />} />
<Route path={searchPath} element={<SearchTracePage />} />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should use relative paths in v7 migration: e.g., search instead of /search

@@ -42,8 +42,7 @@ import '../common/vars.css';
import '../common/utils.css';
import 'antd/dist/reset.css';
import './index.css';
import { history, store } from '../../utils/configure-store';
import { HistoryProvider } from '../../utils/useHistory';
Copy link
Member

Choose a reason for hiding this comment

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

can this module be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not in this PR, other unrelated tests depend on it. We should remove history on its own PR

@@ -20103,7 +19951,7 @@
"@ant-design/compatible": "^5.1.3",
"@jaegertracing/plexus": "0.2.0",
"@pyroscope/flamegraph": "0.21.4",
"@sentry/browser": "^8.48.0",
"@sentry/browser": "^8.18.0",
Copy link
Member

Choose a reason for hiding this comment

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

What causes this downgrade? Before you're running install/uninstall commands, are you on the latest set of dependencies (npm ci)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it seems that the current dep version is 8.18.0?

"@sentry/browser": "^8.18.0",

Copy link
Member

Choose a reason for hiding this comment

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

oh. I hate it when GH glitches like that. It's showing fake diffs, how to even trust its diff...

Copy link
Member

Choose a reason for hiding this comment

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

It is 8.48 in the lock file though:

$ grep sentry/browser package-lock.json
    "node_modules/@sentry/browser": {
      "resolved": "https://registry.npmjs.org/@sentry/browser/-/browser-8.48.0.tgz",
        "@sentry/browser": "^8.48.0",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in the original repo, the current versions in the lock file is 8.48.0 as well.

"version": "8.48.0",

so i updated the version in package.json to match that

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

overall lgtm, but please address questions / comments.

export const ROUTE_PATH = prefixUrl('/trace/:a?\\.\\.\\.:b?');

const ROUTE_MATCHER = { path: ROUTE_PATH, strict: true, exact: true };
export const ROUTE_PATH = prefixUrl('/trace-diff/:a?/:b?');
Copy link
Contributor Author

@Zen-cronic Zen-cronic Jan 14, 2025

Choose a reason for hiding this comment

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

since regex route matching is dropped in rrd v6, a different approach is implemented.

a & b traces are optional dynamic parameters. They're prefixed with /trace-diff instead of /trace b/c /trace/:id is the pattern for TracePage

@@ -2208,7 +2204,6 @@
"resolved": "https://registry.npmjs.org/@ctrl/tinycolor/-/tinycolor-3.6.1.tgz",
"integrity": "sha512-SITSV6aIXsuVNV3f3O0f2n/cgyEDWoSqtZMYiAmcsYHydcKrOz3gUxB/iXd/Qf08+IZX4KpgNbvUdMBmWz+kcA==",
"license": "MIT",
"peer": true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

need be reverted?

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

the Deep Dependency Graph on the Search page stopped working

@Zen-cronic
Copy link
Contributor Author

the Deep Dependency Graph on the Search page stopped working

it might involve converting a few class-based components into functional ones; i'll keep exploring solutions

@yurishkuro
Copy link
Member

If we have to, can we do it in a separate PR and merge it before this one?

@Zen-cronic
Copy link
Contributor Author

the previous commit fixes the error of DDG not being displayed (due to a missing history object for navigation in the class components).

No components were rewritten into function components in this PR, but in this. The rewriting process would block the migration process b/c to use the rrdv6/7 hooks (i.e.g, useLocation, useNavigation) the components must be functional. So, a different workaround is used, explained below:

  • before, the class components (e.g., SearchTracePage, SearchResults, TracesDdgImpl) uses the redux state to keep track of the url params and the location object to check the current url.
  • However, after upgrading to rrdv6, the location object is not in sync with the url in the redux state.
  • So, i passed existing urlQueryParams props and/or a custom prop for the search url to the children components. This resulted in the SearchResults component correctly rendering the DDG:

error-extra-url-query-params

But there are a few errors (so a few tests are failing):

  1. Clicking on a node in the scatter plot should navigate to /trace/:id. The url does change but the respective component is not. That's because the TraceTimelineViewer (& related components) are reading from the redux state which isn't updated.

error-scatter-plot-node

  1. Using the Find search bar while on the DDG page erases the existing url params and removes the graph. This is because the location object that the search bar component reads from is not aware of the other url params:
    const { uiFind: uiFindFromUrl } = parseQuery(state.router.location.search);

error-uifind

  1. Clicking on the Find Traces form by default should set the view params to traces, not ddg:

error-find-traces-should-traces

Signed-off-by: Kaung Zin Hein <[email protected]>
@@ -89,47 +89,21 @@ export default class JaegerUIApp extends Component {
<ConfigProvider theme={jaegerTheme}>
<Provider store={store}>
<HistoryProvider history={history}>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

update: HistoryProvider is still needed by the router b/c history is used for navigation:

history.push(getUrl({ ...urlState, view }));

useNavigate can't be used inside a class-based component.

@@ -36,7 +36,9 @@ const svcOp = memoizeOne((service, operation) => ({ service, operation }));

// export for tests
export function mapStateToProps(state: ReduxState, ownProps: TOwnProps): TReduxProps {
const urlState = getUrlState(ownProps.location.search);
const locationUrlState = getUrlState(ownProps.location.search);
const urlState = { ...locationUrlState, ...ownProps.urlQueryParams };
Copy link
Contributor Author

@Zen-cronic Zen-cronic Jan 16, 2025

Choose a reason for hiding this comment

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

merging with the passed urlQueryParams b/c location and the redux state router are out of sync.

caveat of this approach: we need to do this to every component that are connected to the store and that affect the url in some way

@@ -93,7 +93,7 @@ exports[`DiffSelection renders multiple traces as expected 1`] = `
className="DiffSelection--message"
>
<Link
to="/trace/trace-id-0...trace-id-1?cohort=trace-id-0&cohort=trace-id-1"
to="/trace-diff/trace-id-0/trace-id-1?cohort=trace-id-0&cohort=trace-id-1"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: the second cohort param should be separated by an &

const urlArgs = queryString.parse(location.search);
const { navigateTo } = this.props;

const urlArgs = queryString.parse(navigateTo.split('/search?')[1]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO fix:
parsing the manually passed url prop (that contains the correct params) like this is very hacky.

@Zen-cronic
Copy link
Contributor Author

Blocked by #2588

@Zen-cronic
Copy link
Contributor Author

more issue of useLocation and location not in sync

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:dependencies Update to dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants