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

Migrate annotations to react18 #716

Merged
merged 10 commits into from
Dec 4, 2024

Conversation

mickr
Copy link
Contributor

@mickr mickr commented Nov 20, 2024

This pull request includes several updates and improvements to the codebase, primarily focusing on upgrading dependencies, updating ESLint configurations, and refactoring React-related code to support React 18. The most important changes include updating the ESLint configuration, Typescript upgrade, upgrading various dependencies in package.json, and refactoring ReactDOM usage to align with React 18.

ESLint Configuration Updates:

  • .eslintrc.js: Updated the extends property to include separate configurations for base, react, and typescript. Also, replaced deprecated @typescript-eslint/camelcase rule with @typescript-eslint/naming-convention and added import/no-import-module-exports rule. [1] [2]

Dependency Upgrades:

  • package.json: Upgraded several Babel, ESLint, and React dependencies to their latest versions. Notable changes include upgrading @babel/* packages, eslint and related plugins, and moving from React 17 to React 18. [1] [2] [3] [4] [5] [6]

ReactDOM Refactoring:

Utility and Component Updates:

  • src/components/Popups/Popper.ts: Added clientBoundingRect utility function for consistent DOMRect creation.
  • Various popup components (PopupCursor.tsx, PopupHighlight.tsx, PopupHighlightError.tsx, PopupReply.tsx): Updated to use clientBoundingRect for creating bounding client rectangles. [1] [2] [3] [4] [5] [6] [7]

mickr added 5 commits October 22, 2024 18:00
Migrated codebase from React 17 to React 18. Updated `ReactDOM` imports and usage across multiple files to use `ReactDOM.client`. This included changes to various test files, components, utilities, and the package dependencies.
Simplified import syntax across multiple components, moving from wildcard imports to direct imports. Removed unnecessary `usePrevious` hooks to streamline popup update logic and updated `yarn.lock` to newer versions of several dependencies.
Refactored components to improve readability and consistency. Updated package dependencies and ESLint configurations for better code quality and compatibility with the latest libraries. Adjustments include moving to "react-jsx," improving TypeScript definitions, and simplifying utility functions.
Mocking the entire react-redux module to control useSelector behavior. This ensures test consistency by avoiding real state dependencies.
Replaced `ReactRedux.useSelector` with `useSelector` in PopupReply for consistency. Also, removed unused and commented-out code in global type definitions to improve code clarity.
@mickr mickr requested a review from a team as a code owner November 20, 2024 15:50
Added a directive to disable ESLint checks for undefined variables in the popperMock.js script. This change ensures that the createPopper mock function can be defined without ESLint errors during Jest testing.
Comment on lines 52 to 58
// const removeChildSpy = jest.spyOn(rootEl, 'removeChild');
const wrapper = getWrapper();
const root = ReactDOM.createRoot(rootEl);
wrapper.destroy();

expect(ReactDOM.unmountComponentAtNode).toHaveBeenCalledWith(wrapper.reactEl);
expect(removeChildSpy).toHaveBeenCalledWith(wrapper.reactEl);
expect(root.unmount).toHaveBeenCalled();
// expect(removeChildSpy).toHaveBeenCalledWith(wrapper.reactEl);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like these comments may have got left here on accident. Also, is there an equivalent to removing the node that should be tested?

Comment on lines -100 to 99
if (popup?.popper && (rotation !== prevRotation || scale !== prevScale)) {
if (popup?.popper) {
popup.popper.update();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Will there be any downside to this updating every time? If not, we can also look at removing usePrevious hook since this file looks like only reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I found through testing is that with the new updates in React18 this was no longer getting updated as it was before making the usePrevious hook obsolete.

@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - I saw other files were changed to use import React from 'react';, could that be used here too for consistency?

Comment on lines 163 to 169
// test('should set the root and annotated element based on class name', () => {
// annotator.init(2);
//
// expect(annotator.containerEl).toBe(container);
// expect(annotator.annotatedEl).toBe(getParent());
// expect(annotator.render).toHaveBeenCalled();
// });
Copy link
Contributor

Choose a reason for hiding this comment

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

There are a couple of commented out tests in this file. Are these able to be migrated easily?

Comment on lines 23 to 27
filter_term: searchString,

include_groups: false,

include_uploader_collabs: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - is new line between each intentional?

patlm added 3 commits December 2, 2024 10:58
* In BaseManager, added back deleting the root react node on destroy
* Removed usePrevious files - no longer used
* Added mocks of a mangager to fix ImageAnnotator unit tests of getReference and init functions
* Minor style changes
@@ -35,6 +35,7 @@ export default function DrawingCreator({
const drawingPathRef = React.useRef<DrawingPathRef>(null);
const drawingSVGRef = React.useRef<DrawingSVGRef>(null);
const renderHandleRef = React.useRef<number | null>(null);
// eslint-disable-next-line react-hooks/exhaustive-deps

Choose a reason for hiding this comment

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

Is this needed here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was able to change it to use useMemo instead.

"@types/react": "^17.0.2",
"@types/react-dom": "^17.0.1",
"@types/react-redux": "^7.1.16",
"@types/react": "18.3.12",

Choose a reason for hiding this comment

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

Why is there a type mismatch between @types/react and react?

Copy link
Contributor

Choose a reason for hiding this comment

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

I found this thread about it. The DefinitelyTyped library uses major and minor versions that match the corresponding library but varies on patch version.

ahorowitz123
ahorowitz123 previously approved these changes Dec 3, 2024
@mergify mergify bot merged commit cf6a34c into box:master Dec 4, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants