Skip to content

Commit 6f6b8bd

Browse files
authored
feat!: upgrade to react v18 (#998)
1 parent cdd11f0 commit 6f6b8bd

File tree

9 files changed

+94
-299
lines changed

9 files changed

+94
-299
lines changed

library/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,25 @@
7676
"isomorphic-dompurify": "^0.13.0",
7777
"marked": "^4.0.14",
7878
"openapi-sampler": "^1.2.1",
79-
"use-resize-observer": "^8.0.0"
79+
"use-resize-observer": "^9.1.0"
8080
},
8181
"peerDependencies": {
82-
"react": ">=16.8.0",
83-
"react-dom": ">=16.8.0"
82+
"react": ">=18.0.0",
83+
"react-dom": ">=18.0.0"
8484
},
8585
"devDependencies": {
8686
"@cypress/webpack-preprocessor": "^5.9.0",
8787
"@tailwindcss/typography": "^0.4.0",
8888
"@testing-library/jest-dom": "^5.17.0",
89-
"@testing-library/react": "^12.1.5",
89+
"@testing-library/react": "^15.0.4",
9090
"@testing-library/user-event": "^12.8.3",
9191
"@types/dompurify": "^2.0.4",
9292
"@types/highlight.js": "^10.1.0",
9393
"@types/jest": "^26.0.23",
9494
"@types/marked": "^4.0.1",
9595
"@types/node": "^12.7.2",
96-
"@types/react": "^16.9.2",
97-
"@types/react-dom": "^17.0.3",
96+
"@types/react": "^18.2.79",
97+
"@types/react-dom": "^18.2.25",
9898
"autoprefixer": "^10.2.5",
9999
"cross-env": "^7.0.3",
100100
"cssnano": "^4.1.11",
@@ -105,8 +105,8 @@
105105
"postcss-cli": "^8.3.1",
106106
"postcss-import": "^14.0.2",
107107
"postcss-scopify": "^0.1.9",
108-
"react": "^16.8.0",
109-
"react-dom": "^16.8.0",
108+
"react": "^18.2.0",
109+
"react-dom": "^18.2.0",
110110
"tailwindcss": "^2.1.1",
111111
"ts-jest": "^26.4.1",
112112
"ts-loader": "9.4.4",

library/src/components/Href.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ interface Props {
44
href: string;
55
title?: string;
66
className?: string;
7+
children: React.ReactNode;
78
}
89

910
export const Href: React.FunctionComponent<Props> = ({

library/src/components/Markdown.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { sanitize } from 'isomorphic-dompurify';
33

44
import { renderMarkdown } from '../helpers';
55

6-
export const Markdown: React.FunctionComponent = ({ children }) => {
6+
export const Markdown: React.FunctionComponent<{
7+
children: React.ReactNode;
8+
}> = ({ children }) => {
79
if (!children) {
810
return null;
911
}

library/src/containers/Servers/Security.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const Security: React.FunctionComponent<Props> = ({
2727
);
2828
}
2929
} else {
30-
const securities: React.ReactNodeArray = Object.values(security)
30+
const securities: React.ReactNode[] = Object.values(security)
3131
.map((requirements) => requirements.all())
3232
.flat()
3333
.map((requirement) => {
@@ -74,8 +74,8 @@ export const Security: React.FunctionComponent<Props> = ({
7474
function collectSecuritySchemas(
7575
securitySchema: SecuritySchemeInterface | null,
7676
requiredScopes: string[] = [],
77-
): React.ReactNodeArray {
78-
const schemas: React.ReactNodeArray = [];
77+
): React.ReactNode[] {
78+
const schemas: React.ReactNode[] = [];
7979
if (securitySchema) {
8080
if (securitySchema.name()) {
8181
schemas.push(<span>Name: {securitySchema.name()}</span>);
@@ -114,7 +114,7 @@ const SecurityItem: React.FunctionComponent<SecurityItemProps> = ({
114114
protocol,
115115
requiredScopes,
116116
}) => {
117-
const schemas: React.ReactNodeArray = collectSecuritySchemas(
117+
const schemas: React.ReactNode[] = collectSecuritySchemas(
118118
securitySchema,
119119
requiredScopes,
120120
);

library/src/containers/Sidebar/Sidebar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ const ServerItem: React.FunctionComponent<ServerItemProps> = ({
388388

389389
interface ItemsByTagItemProps {
390390
tagName: string;
391+
children: React.ReactNode;
391392
}
392393

393394
const ItemsByTagItem: React.FunctionComponent<ItemsByTagItemProps> = ({

library/src/standalone-codebase.ts

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import React from 'react';
2-
import {
3-
// eslint-disable-next-line react/no-deprecated
4-
hydrate as hydrateComponent,
5-
// eslint-disable-next-line react/no-deprecated
6-
render as renderComponent,
7-
} from 'react-dom';
8-
9-
function querySelector(selector: string): Element | DocumentFragment | null {
2+
import { hydrateRoot, createRoot } from 'react-dom/client';
3+
4+
function querySelector(selector: string): Element | null {
105
if (typeof document !== 'undefined') {
116
return document.querySelector(selector);
127
}
@@ -18,20 +13,19 @@ function querySelector(selector: string): Element | DocumentFragment | null {
1813
*
1914
* @param {Any} component of any kind
2015
*/
21-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
22-
export function createRender<P extends object>(component: any) {
23-
return (
24-
props: P,
25-
container?: Element | DocumentFragment | null,
26-
callback?: () => void,
27-
) => {
16+
export function createRender<
17+
Props extends Parameters<typeof React.createElement>[1],
18+
>(component: Parameters<typeof React.createElement>[0]) {
19+
return (props: Props, container?: Element | DocumentFragment | null) => {
2820
container = container ?? querySelector('asyncapi');
21+
2922
if (container === null) {
3023
return;
3124
}
3225

33-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
34-
renderComponent(React.createElement(component, props), container, callback);
26+
const root = createRoot(container);
27+
28+
root.render(React.createElement(component, props));
3529
};
3630
}
3731

@@ -40,23 +34,16 @@ export function createRender<P extends object>(component: any) {
4034
*
4135
* @param {Any} component of any kind
4236
*/
43-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
44-
export function createHydrate<P extends object>(component: any) {
45-
return (
46-
props: P,
47-
container?: Element | DocumentFragment | null,
48-
callback?: () => void,
49-
) => {
37+
export function createHydrate<
38+
Props extends Parameters<typeof React.createElement>[1],
39+
>(component: Parameters<typeof React.createElement>[0]) {
40+
return (props: Props, container?: Element | Document | null) => {
5041
container = container ?? querySelector('asyncapi');
42+
5143
if (container === null) {
5244
return;
5345
}
5446

55-
hydrateComponent(
56-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
57-
React.createElement(component, props),
58-
container,
59-
callback,
60-
);
47+
hydrateRoot(container, React.createElement(component, props));
6148
};
6249
}

0 commit comments

Comments
 (0)