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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

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]

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

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

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

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

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

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?

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

Successfully merging this pull request may close these issues.

2 participants