Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 317ffcf

Browse files
committed
Update to React 18
Signed-off-by: Michael Telatynski <[email protected]>
1 parent 17506f7 commit 317ffcf

37 files changed

+132
-165
lines changed

package.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
"lint:workflows": "find .github/workflows -type f \\( -iname '*.yaml' -o -iname '*.yml' \\) | xargs -I {} sh -c 'echo \"Linting {}\"; action-validator \"{}\"'"
6464
},
6565
"resolutions": {
66-
"@types/react-dom": "17.0.25",
67-
"@types/react": "17.0.80",
66+
"@types/react-dom": "18.3.0",
67+
"@types/react": "18.3.3",
6868
"@types/seedrandom": "3.0.8",
6969
"oidc-client-ts": "3.0.1",
7070
"jwt-decode": "4.0.0",
@@ -81,7 +81,6 @@
8181
"@matrix-org/react-sdk-module-api": "^2.4.0",
8282
"@matrix-org/spec": "^1.7.0",
8383
"@sentry/browser": "^8.0.0",
84-
"@testing-library/react-hooks": "^8.0.1",
8584
"@vector-im/compound-design-tokens": "^1.6.1",
8685
"@vector-im/compound-web": "^5.5.0",
8786
"@zxcvbn-ts/core": "^3.0.4",
@@ -129,10 +128,10 @@
129128
"posthog-js": "1.149.1",
130129
"qrcode": "1.5.3",
131130
"re-resizable": "^6.9.0",
132-
"react": "17.0.2",
131+
"react": "^18.3.1",
133132
"react-beautiful-dnd": "^13.1.0",
134133
"react-blurhash": "^0.3.0",
135-
"react-dom": "17.0.2",
134+
"react-dom": "^18.3.1",
136135
"react-focus-lock": "^2.5.1",
137136
"react-transition-group": "^4.4.1",
138137
"rfc4648": "^1.4.0",
@@ -167,7 +166,7 @@
167166
"@playwright/test": "^1.40.1",
168167
"@testing-library/dom": "^9.0.0",
169168
"@testing-library/jest-dom": "^6.0.0",
170-
"@testing-library/react": "^12.1.5",
169+
"@testing-library/react": "^14",
171170
"@testing-library/user-event": "^14.4.3",
172171
"@types/commonmark": "^0.27.4",
173172
"@types/content-type": "^1.1.5",
@@ -187,9 +186,9 @@
187186
"@types/node-fetch": "^2.6.2",
188187
"@types/pako": "^2.0.0",
189188
"@types/qrcode": "^1.3.5",
190-
"@types/react": "17.0.80",
189+
"@types/react": "18.3.3",
191190
"@types/react-beautiful-dnd": "^13.0.0",
192-
"@types/react-dom": "17.0.25",
191+
"@types/react-dom": "18.3.0",
193192
"@types/react-transition-group": "^4.4.0",
194193
"@types/sanitize-html": "2.11.0",
195194
"@types/sdp-transform": "^2.4.6",
@@ -246,6 +245,10 @@
246245
"postcss": "^8.4.19",
247246
"webpack": "^4.0.0 || ^5.0.0"
248247
},
248+
"peerDependencies": {
249+
"postcss": "^8.4.19",
250+
"webpack": "^4.0.0 || ^5.0.0"
251+
},
249252
"@casualbot/jest-sonar-reporter": {
250253
"outputDirectory": "coverage",
251254
"outputName": "jest-sonar-report.xml",

src/@types/react.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ declare module "react" {
2121
function forwardRef<T, P = {}>(
2222
render: (props: PropsWithChildren<P>, ref: React.ForwardedRef<T>) => React.ReactElement | null,
2323
): (props: P & React.RefAttributes<T>) => React.ReactElement | null;
24+
25+
// Fix lazy types - https://stackoverflow.com/a/71017028
26+
function lazy<T extends ComponentType<any>>(factory: () => Promise<{ default: T }>): T;
2427
}

src/NodeAnimator.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import React, { Key, MutableRefObject, ReactElement, ReactFragment, ReactInstance, ReactPortal } from "react";
17+
import React, { Key, MutableRefObject, ReactElement, ReactInstance } from "react";
1818
import ReactDom from "react-dom";
1919

2020
interface IChildProps {
@@ -35,7 +35,7 @@ interface IProps {
3535
innerRef?: MutableRefObject<any>;
3636
}
3737

38-
function isReactElement(c: ReactElement | ReactFragment | ReactPortal): c is ReactElement {
38+
function isReactElement(c: ReturnType<(typeof React.Children)["toArray"]>[number]): c is ReactElement {
3939
return typeof c === "object" && "type" in c;
4040
}
4141

@@ -110,7 +110,8 @@ export default class NodeAnimator extends React.Component<IProps> {
110110
}
111111

112112
private collectNode(k: Key, node: React.ReactInstance, restingStyle: React.CSSProperties): void {
113-
if (node && this.nodes[k] === undefined && this.props.startStyles.length > 0) {
113+
const key = typeof k === "bigint" ? Number(k) : k;
114+
if (node && this.nodes[key] === undefined && this.props.startStyles.length > 0) {
114115
const startStyles = this.props.startStyles;
115116
const domNode = ReactDom.findDOMNode(node);
116117
// start from startStyle 1: 0 is the one we gave it
@@ -124,7 +125,7 @@ export default class NodeAnimator extends React.Component<IProps> {
124125
this.applyStyles(domNode as HTMLElement, restingStyle);
125126
}, 0);
126127
}
127-
this.nodes[k] = node;
128+
this.nodes[key] = node;
128129

129130
if (this.props.innerRef) {
130131
this.props.innerRef.current = node;

src/components/structures/GenericDropdownMenu.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ type WithKeyFunction<T> = T extends Key
9797
toKey: (key: T) => Key;
9898
};
9999

100+
export interface AdditionalOptionsProps {
101+
menuDisplayed: boolean;
102+
closeMenu: () => void;
103+
openMenu: () => void;
104+
}
105+
100106
type IProps<T> = WithKeyFunction<T> & {
101107
value: T;
102108
options: readonly GenericDropdownMenuOption<T>[] | readonly GenericDropdownMenuGroup<T>[];
@@ -105,11 +111,7 @@ type IProps<T> = WithKeyFunction<T> & {
105111
onOpen?: (ev: ButtonEvent) => void;
106112
onClose?: (ev: ButtonEvent) => void;
107113
className?: string;
108-
AdditionalOptions?: FunctionComponent<{
109-
menuDisplayed: boolean;
110-
closeMenu: () => void;
111-
openMenu: () => void;
112-
}>;
114+
AdditionalOptions?: FunctionComponent<AdditionalOptionsProps>;
113115
};
114116

115117
export function GenericDropdownMenu<T>({

src/components/structures/ThreadPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export const ThreadPanelHeader: React.FC<{
117117
) : null;
118118

119119
const onMarkAllThreadsReadClick = React.useCallback(
120-
(e) => {
120+
(e: React.MouseEvent) => {
121121
PosthogTrackers.trackInteraction("WebThreadsMarkAllReadButton", e);
122122
if (!roomContext.room) {
123123
logger.error("No room in context to mark all threads read");

src/components/views/avatars/BaseAvatar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ limitations under the License.
1919

2020
import React, { forwardRef, useCallback, useContext, useEffect, useState } from "react";
2121
import classNames from "classnames";
22-
import { ClientEvent } from "matrix-js-sdk/src/matrix";
22+
import { ClientEvent, SyncState } from "matrix-js-sdk/src/matrix";
2323
import { Avatar } from "@vector-im/compound-web";
2424

2525
import SettingsStore from "../../../settings/SettingsStore";
@@ -80,7 +80,7 @@ const useImageUrl = ({ url, urls }: { url?: string | null; urls?: string[] }): [
8080
}, [url, JSON.stringify(urls)]); // eslint-disable-line react-hooks/exhaustive-deps
8181

8282
const cli = useContext(MatrixClientContext);
83-
const onClientSync = useCallback((syncState, prevState) => {
83+
const onClientSync = useCallback((syncState: SyncState, prevState: SyncState | null) => {
8484
// Consider the client reconnected if there is no error with syncing.
8585
// This means the state could be RECONNECTING, SYNCING, PREPARED or CATCHUP.
8686
const reconnected = syncState !== "ERROR" && prevState !== syncState;

src/components/views/dialogs/spotlight/Option.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ interface OptionProps {
2626
id?: string;
2727
className?: string;
2828
onClick: ((ev: ButtonEvent) => void) | null;
29+
children?: ReactNode;
2930
}
3031

3132
export const Option: React.FC<OptionProps> = ({ inputRef, children, endAdornment, className, ...props }) => {

src/components/views/directory/NetworkDropdown.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ import SdkConfig from "../../../SdkConfig";
2626
import { SettingLevel } from "../../../settings/SettingLevel";
2727
import SettingsStore from "../../../settings/SettingsStore";
2828
import { Protocols } from "../../../utils/DirectoryUtils";
29-
import { GenericDropdownMenu, GenericDropdownMenuItem } from "../../structures/GenericDropdownMenu";
29+
import {
30+
AdditionalOptionsProps,
31+
GenericDropdownMenu,
32+
GenericDropdownMenuItem,
33+
} from "../../structures/GenericDropdownMenu";
3034
import TextInputDialog from "../dialogs/TextInputDialog";
3135
import AccessibleButton from "../elements/AccessibleButton";
3236
import withValidation from "../elements/Validation";
@@ -181,7 +185,7 @@ export const NetworkDropdown: React.FC<IProps> = ({ protocols, config, setConfig
181185
}));
182186

183187
const addNewServer = useCallback(
184-
({ closeMenu }) => (
188+
({ closeMenu }: AdditionalOptionsProps) => (
185189
<>
186190
<span className="mx_GenericDropdownMenu_divider" />
187191
<MenuItemRadio

src/components/views/elements/PersistentApp.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
1515
limitations under the License.
1616
*/
1717

18-
import React, { ContextType, CSSProperties, MutableRefObject } from "react";
18+
import React, { ContextType, CSSProperties, MutableRefObject, ReactNode } from "react";
1919
import { Room } from "matrix-js-sdk/src/matrix";
2020

2121
import WidgetUtils from "../../../utils/WidgetUtils";
@@ -28,6 +28,7 @@ interface IProps {
2828
persistentRoomId: string;
2929
pointerEvents?: CSSProperties["pointerEvents"];
3030
movePersistedElement: MutableRefObject<(() => void) | undefined>;
31+
children?: ReactNode;
3132
}
3233

3334
export default class PersistentApp extends React.Component<IProps> {

src/components/views/messages/RoomPredecessorTile.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717

1818
import React, { useCallback, useContext } from "react";
1919
import { logger } from "matrix-js-sdk/src/logger";
20-
import { MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
20+
import { MatrixEvent, Room, RoomState } from "matrix-js-sdk/src/matrix";
2121

2222
import dis from "../../../dispatcher/dispatcher";
2323
import { Action } from "../../../dispatcher/actions";
@@ -52,7 +52,7 @@ export const RoomPredecessorTile: React.FC<IProps> = ({ mxEvent, timestamp }) =>
5252
const predecessor = useRoomState(
5353
roomContext.room,
5454
useCallback(
55-
(state) => state.findPredecessor(msc3946ProcessDynamicPredecessor),
55+
(state: RoomState) => state.findPredecessor(msc3946ProcessDynamicPredecessor),
5656
[msc3946ProcessDynamicPredecessor],
5757
),
5858
);
@@ -63,9 +63,9 @@ export const RoomPredecessorTile: React.FC<IProps> = ({ mxEvent, timestamp }) =>
6363

6464
dis.dispatch<ViewRoomPayload>({
6565
action: Action.ViewRoom,
66-
event_id: predecessor.eventId,
66+
event_id: predecessor?.eventId,
6767
highlighted: true,
68-
room_id: predecessor.roomId,
68+
room_id: predecessor?.roomId,
6969
metricsTrigger: "Predecessor",
7070
metricsViaKeyboard: e.type !== "click",
7171
});
@@ -126,7 +126,7 @@ export const RoomPredecessorTile: React.FC<IProps> = ({ mxEvent, timestamp }) =>
126126

127127
const predecessorPermalink = prevRoom
128128
? createLinkWithRoom(prevRoom, predecessor.roomId, predecessor.eventId)
129-
: createLinkWithoutRoom(predecessor.roomId, predecessor.viaServers, predecessor.eventId);
129+
: createLinkWithoutRoom(predecessor.roomId, predecessor?.viaServers ?? [], predecessor.eventId);
130130

131131
const link = (
132132
<a href={predecessorPermalink} onClick={onLinkClicked}>

0 commit comments

Comments
 (0)