Skip to content

Commit

Permalink
Upgrade project to React 18 (#6941)
Browse files Browse the repository at this point in the history
* chore: bump react version

* fix: use createRoot instead of render

* fix: fix some more imports & remove hot loader

* fix: update testing library and fix tests

* fix: fix some warnings in tests

* chore: update deps for new packages

* fix: uuid import in relation control
  • Loading branch information
demshy authored Oct 20, 2023
1 parent b2160f7 commit f8cb458
Show file tree
Hide file tree
Showing 38 changed files with 1,545 additions and 3,933 deletions.
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@
"@emotion/jest": "^11.11.0",
"@octokit/rest": "^16.28.7",
"@soda/friendly-errors-webpack-plugin": "^1.8.1",
"@storybook/addon-actions": "^5.3.6",
"@storybook/addon-links": "^5.3.6",
"@storybook/react": "^5.3.6",
"@storybook/addon-actions": "^7.5.1",
"@storybook/addon-links": "^7.5.1",
"@storybook/react": "^7.5.1",
"@stylelint/postcss-css-in-js": "^0.37.2",
"@testing-library/dom": "^8.0.0",
"@testing-library/jest-dom": "^5.11.1",
"@testing-library/react": "^12.0.0",
"@testing-library/react": "^14.0.0",
"@types/common-tags": "^1.8.0",
"@types/jest": "^27.0.0",
"@types/js-base64": "^3.0.0",
Expand Down Expand Up @@ -152,10 +152,9 @@
"postcss": "^8.4.7",
"postcss-scss": "^4.0.3",
"prettier": "^2.3.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-hot-loader": "^4.13.1",
"react-test-renderer": "^16.8.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-test-renderer": "^18.2.0",
"rehype": "^7.0.0",
"rimraf": "^3.0.0",
"simple-git": "^3.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/decap-cms-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
"uuid": "^8.3.2"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"incrementToForceBump": 2
}
2 changes: 1 addition & 1 deletion packages/decap-cms-backend-azure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"immutable": "^3.7.6",
"lodash": "^4.17.11",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0"
"react": "^18.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-backend-bitbucket/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"immutable": "^3.7.6",
"lodash": "^4.17.11",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0"
"react": "^18.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-backend-git-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"decap-cms-ui-default": "^3.0.0",
"lodash": "^4.17.11",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0"
"react": "^18.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-backend-gitea/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"immutable": "^3.7.6",
"lodash": "^4.17.11",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0"
"react": "^18.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-backend-github/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
"decap-cms-ui-default": "^3.0.0",
"lodash": "^4.17.11",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0"
"react": "^18.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-backend-gitlab/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
"immutable": "^3.7.6",
"lodash": "^4.17.11",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0"
"react": "^18.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-backend-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"decap-cms-lib-util": "^3.0.0",
"decap-cms-ui-default": "^3.0.0",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0"
"react": "^18.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-backend-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"decap-cms-ui-default": "^3.0.0",
"lodash": "^4.17.11",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0",
"react": "^18.2.0",
"uuid": "^8.3.2"
}
}
9 changes: 4 additions & 5 deletions packages/decap-cms-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@
"jwt-decode": "^3.0.0",
"node-polyglot": "^2.3.0",
"prop-types": "^15.7.2",
"react": "^16.8.4",
"react": "^18.2.0",
"react-dnd": "^14.0.0",
"react-dnd-html5-backend": "^14.0.0",
"react-dom": "^16.8.4",
"react-dom": "^18.2.0",
"react-frame-component": "^5.2.1",
"react-hot-loader": "^4.8.0",
"react-immutable-proptypes": "^2.1.0",
"react-is": "16.13.1",
"react-markdown": "^6.0.2",
Expand Down Expand Up @@ -87,8 +86,8 @@
"lodash": "^4.17.11",
"moment": "^2.24.0",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-immutable-proptypes": "^2.1.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Map } from 'immutable';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { mocked } from 'ts-jest/utils';
import { mocked } from 'jest-mock';

import { getAsset, ADD_ASSET, LOAD_ASSET_REQUEST } from '../media';
import { selectMediaFilePath } from '../../reducers/entries';
Expand Down
5 changes: 3 additions & 2 deletions packages/decap-cms-core/src/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render } from 'react-dom';
import { createRoot } from 'react-dom/client';
import { Provider, connect } from 'react-redux';
import { Route, Router } from 'react-router-dom';
import { GlobalStyles } from 'decap-cms-ui-default';
Expand Down Expand Up @@ -96,7 +96,8 @@ function bootstrap(opts = {}) {
/**
* Render application root.
*/
render(<Root />, getRoot());
const root = createRoot(getRoot());
root.render(<Root />);
}

export default bootstrap;
3 changes: 1 addition & 2 deletions packages/decap-cms-core/src/components/App/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import PropTypes from 'prop-types';
import React from 'react';
import { hot } from 'react-hot-loader';
import { translate } from 'react-polyglot';
import ImmutablePropTypes from 'react-immutable-proptypes';
import styled from '@emotion/styled';
Expand Down Expand Up @@ -277,4 +276,4 @@ const mapDispatchToProps = {
logoutUser,
};

export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(translate()(App)));
export default connect(mapStateToProps, mapDispatchToProps)(translate()(App));
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ describe('Editor', () => {
expect(asFragment()).toMatchSnapshot();
expect(console.error).toHaveBeenCalledTimes(1);
expect(console.error).toHaveBeenCalledWith(
'Warning: Failed prop type: Required prop `entryDraft` was not specified in `Editor`.\n in Editor',
'Warning: Failed %s type: %s%s',
'prop',
'Required prop `entryDraft` was not specified in `Editor`.',
expect.anything(),
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createHashHistory } from 'history';
import { mocked } from 'ts-jest/utils';
import { mocked } from 'jest-mock';

import type { History } from 'history';

Expand Down
4 changes: 2 additions & 2 deletions packages/decap-cms-default-exports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"uuid": "^8.3.2"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-editor-component-image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"cross-env": "^7.0.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0"
"react": "^18.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-ui-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"@emotion/styled": "^11.11.0",
"lodash": "^4.17.11",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0"
"react": "^18.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-widget-boolean/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"decap-cms-ui-default": "^3.0.0",
"lodash": "^4.17.11",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0",
"react": "^18.2.0",
"react-immutable-proptypes": "^2.1.0"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-widget-code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"codemirror": "^5.46.0",
"decap-cms-ui-default": "^3.0.0",
"lodash": "^4.17.11",
"react": "^16.8.4 || ^17.0.0"
"react": "^18.2.0"
},
"dependencies": {
"react-codemirror2": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/decap-cms-widget-colorstring/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"@emotion/styled": "^11.11.0",
"decap-cms-ui-default": "^3.0.0",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0"
"react": "^18.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-widget-datetime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"peerDependencies": {
"@emotion/react": "^11.11.1",
"react": "^16.8.4 || ^17.0.0"
"react": "^18.2.0"
},
"dependencies": {
"react-datetime": "^3.1.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/decap-cms-widget-file/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"decap-cms-ui-default": "^3.0.0",
"immutable": "^3.7.6",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0",
"react": "^18.2.0",
"react-immutable-proptypes": "^2.1.0",
"uuid": "^8.3.2"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/decap-cms-widget-image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"decap-cms-widget-file": "^3.0.0",
"immutable": "^3.7.6",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0"
"react": "^18.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-widget-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"immutable": "^3.7.6",
"lodash": "^4.17.11",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0",
"react": "^18.2.0",
"react-immutable-proptypes": "^2.1.0"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-widget-map/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"decap-cms-ui-default": "^3.0.0",
"lodash": "^4.17.11",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0",
"react": "^18.2.0",
"react-immutable-proptypes": "^2.1.0"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/decap-cms-widget-markdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"immutable": "^3.7.6",
"lodash": "^4.17.11",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-immutable-proptypes": "^2.1.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/decap-cms-widget-number/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"peerDependencies": {
"decap-cms-ui-default": "^3.0.0",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0"
"react": "^18.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-widget-object/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"immutable": "^3.7.6",
"lodash": "^4.17.11",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0",
"react": "^18.2.0",
"react-immutable-proptypes": "^2.1.0"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-widget-relation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"immutable": "^3.7.6",
"lodash": "^4.17.11",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0",
"react": "^18.2.0",
"uuid": "^8.3.2"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-widget-relation/src/RelationControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { SortableContext, horizontalListSortingStrategy, useSortable } from '@dnd-kit/sortable';
import { restrictToParentElement } from '@dnd-kit/modifiers';
import { CSS } from '@dnd-kit/utilities';
import uuid from 'uuid';
import { v4 as uuid } from 'uuid';

function arrayMove(array, from, to) {
const slicedArray = array.slice();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { fromJS } from 'immutable';
import { render, fireEvent, waitFor } from '@testing-library/react';
import { render, fireEvent, waitFor, act } from '@testing-library/react';

import { DecapCmsWidgetRelation } from '../';

Expand Down Expand Up @@ -151,12 +151,16 @@ class RelationController extends React.Component {
}

handleOnChange = jest.fn(value => {
this.setState({ ...this.state, value });
act(() => {
this.setState({ ...this.state, value });
});
});

setQueryHits = jest.fn(queryHits => {
if (this.mounted) {
this.setState({ ...this.state, queryHits });
act(() => {
this.setState({ ...this.state, queryHits });
});
}
});

Expand Down
2 changes: 1 addition & 1 deletion packages/decap-cms-widget-select/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"decap-cms-ui-default": "^3.0.0",
"immutable": "^3.7.6",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0",
"react": "^18.2.0",
"react-immutable-proptypes": "^2.1.0"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/decap-cms-widget-string/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"peerDependencies": {
"decap-cms-ui-default": "^3.0.0",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0"
"react": "^18.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/decap-cms-widget-text/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"peerDependencies": {
"decap-cms-ui-default": "^3.0.0",
"prop-types": "^15.7.2",
"react": "^16.8.4 || ^17.0.0"
"react": "^18.2.0"
}
}
5 changes: 2 additions & 3 deletions packages/decap-cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
"decap-cms-media-library-cloudinary": "^3.0.1",
"decap-cms-media-library-uploadcare": "^3.0.0",
"file-loader": "^6.2.0",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-hot-loader": "^4.13.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"svgo-loader": "^3.0.3"
},
"incrementToForceBump": 2
Expand Down
Loading

0 comments on commit f8cb458

Please sign in to comment.