Skip to content
19 changes: 0 additions & 19 deletions packages/jaeger-ui/src/utils/withRouteProps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,8 @@ import { render } from '@testing-library/react';
import { MemoryRouter, Route, Routes } from 'react-router-dom-v5-compat';
import withRouteProps from './withRouteProps';

jest.mock('./configure-store', () => ({
history: {
push: jest.fn(),
replace: jest.fn(),
go: jest.fn(),
goBack: jest.fn(),
goForward: jest.fn(),
block: jest.fn(),
listen: jest.fn(),
createHref: jest.fn(),
action: 'POP',
length: 1,
location: { pathname: '/test', search: '?param=value' },
},
store: {},
}));

describe('withRouteProps', () => {
test('passes route props to WrappedComponent', () => {
const { history: mockHistory } = require('./configure-store');
const WrappedComponent = jest.fn(() => null);
const ComponentWithRouteProps = withRouteProps(WrappedComponent);
render(
Expand All @@ -46,7 +28,6 @@ describe('withRouteProps', () => {
pathname: '/test',
search: '?param=value',
params: {},
history: mockHistory,
})
);
});
Expand Down
21 changes: 5 additions & 16 deletions packages/jaeger-ui/src/utils/withRouteProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,21 @@
// SPDX-License-Identifier: Apache-2.0

import React from 'react';
import { useLocation, useParams } from 'react-router-dom-v5-compat';
import { History, Location } from 'history';
import { history } from './configure-store';
import { useLocation, useParams } from 'react-router-dom';

/**
* Interface representing route-related props passed to the enhanced component.
* @interface
* @property {Location} location - The current location object containing information about the URL.
* @property {ReturnType<typeof useLocation>} location - The current location object
* @property {string} pathname - The current URL pathname.
* @property {string} search - The current URL search string.
* @property {object} params - The URL parameters.
* @property {History} history - The history object for navigation.
*/
export type IWithRouteProps = {
location: Location;
location: ReturnType<typeof useLocation>;
pathname: string;
search: string;
params: object;
history: History;
};

/**
Expand All @@ -38,7 +34,7 @@ export default function withRouteProps(WrappedComponent: React.ElementType) {
return function WithRouteProps(props: IWithRouteProps | object) {
/**
* The current location object containing information about the URL.
* @type {Location}
* @type {ReturnType<typeof useLocation>}
*/
const location = useLocation();

Expand All @@ -65,14 +61,7 @@ export default function withRouteProps(WrappedComponent: React.ElementType) {
* @returns {React.Component} The enhanced component with additional route-related props.
*/
return (
<WrappedComponent
{...props}
location={location}
pathname={pathname}
search={search}
params={params}
history={history}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So we're no longer passing history, how is it not a breaking change? THIS file may not need history but we have no idea if the WrappedComponent needs it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The test update was meant to reflect the current behavior of withRouteProps, which no longer injects history now that routing is handled via hooks.That said, I agree this HOC could still be used by components that expect history, so removing it may be a breaking change depending on usage.
I’m happy to update this in either direction:

  1. keep passing history for backward compatibility, or
  2. clarify and/or deprecate the behavior explicitly if that’s the intended direction.

Let me know what you’d prefer and I’ll adjust accordingly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/>
<WrappedComponent {...props} location={location} pathname={pathname} search={search} params={params} />
);
};
}
Loading