Skip to content

Commit 7dab56e

Browse files
committed
Type fixes for react v19 compatibility
Two things: - import `JSX` rather than expecting it to be a global namespace - require a default value for `useRef` I found these whilst working on #2874
1 parent d985bd3 commit 7dab56e

17 files changed

+32
-15
lines changed

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only
55
Please see LICENSE in the repository root for full details.
66
*/
77

8-
import { type FC, Suspense, useEffect, useState } from "react";
8+
import { type FC, type JSX, Suspense, useEffect, useState } from "react";
99
import { BrowserRouter, Route, useLocation, Routes } from "react-router-dom";
1010
import * as Sentry from "@sentry/react";
1111
import { TooltipProvider } from "@vector-im/compound-web";

src/ClientContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
useContext,
1515
useRef,
1616
useMemo,
17+
type JSX,
1718
} from "react";
1819
import { useNavigate } from "react-router-dom";
1920
import { logger } from "matrix-js-sdk/src/logger";

src/auth/useInteractiveRegistration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const useInteractiveRegistration = (
3939
undefined,
4040
);
4141

42-
const authClient = useRef<MatrixClient>();
42+
const authClient = useRef<MatrixClient | undefined>(undefined);
4343
if (!authClient.current) {
4444
authClient.current = createClient({
4545
baseUrl: Config.defaultHomeserverUrl()!,

src/auth/useRecaptcha.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function useRecaptcha(sitekey?: string): {
3232
} {
3333
const { t } = useTranslation();
3434
const [recaptchaId] = useState(() => randomString(16));
35-
const promiseRef = useRef<RecaptchaPromiseRef>();
35+
const promiseRef = useRef<RecaptchaPromiseRef | undefined>(undefined);
3636

3737
useEffect(() => {
3838
if (!sitekey) return;

src/grid/TileWrapper.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ SPDX-License-Identifier: AGPL-3.0-only
55
Please see LICENSE in the repository root for full details.
66
*/
77

8-
import { type ComponentType, memo, type RefObject, useRef } from "react";
8+
import {
9+
type ComponentType,
10+
type JSX,
11+
memo,
12+
type RefObject,
13+
useRef,
14+
} from "react";
915
import { type EventTypes, type Handler, useDrag } from "@use-gesture/react";
1016
import { type SpringValue } from "@react-spring/web";
1117
import classNames from "classnames";

src/input/Input.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
forwardRef,
1313
type ReactNode,
1414
useId,
15+
type JSX,
1516
} from "react";
1617
import classNames from "classnames";
1718

src/input/StarRatingInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Copyright 2023, 2024 New Vector Ltd.
44
SPDX-License-Identifier: AGPL-3.0-only
55
Please see LICENSE in the repository root for full details.
66
*/
7-
import { useState } from "react";
7+
import { useState, type JSX } from "react";
88
import { useTranslation } from "react-i18next";
99

1010
import styles from "./StarRatingInput.module.css";

src/livekit/MediaDevicesContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
useMemo,
1515
useRef,
1616
useState,
17+
type JSX,
1718
} from "react";
1819
import { createMediaDeviceObserver } from "@livekit/components-core";
1920
import { map, startWith } from "rxjs";

src/reactions/useReactionsSender.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
type ReactNode,
1313
useCallback,
1414
useMemo,
15+
type JSX,
1516
} from "react";
1617
import { type MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
1718
import { logger } from "matrix-js-sdk/src/logger";

src/room/GroupCallView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ export const GroupCallView: FC<Props> = ({
154154
);
155155

156156
const deviceContext = useMediaDevices();
157-
const latestDevices = useRef<MediaDevices>();
157+
const latestDevices = useRef<MediaDevices | undefined>(undefined);
158158
latestDevices.current = deviceContext;
159159

160160
// TODO: why do we use a ref here instead of using muteStates directly?
161-
const latestMuteStates = useRef<MuteStates>();
161+
const latestMuteStates = useRef<MuteStates | undefined>(undefined);
162162
latestMuteStates.current = muteStates;
163163

164164
useEffect(() => {

src/room/InCallView.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
useMemo,
2424
useRef,
2525
useState,
26+
type JSX,
2627
} from "react";
2728
import useMeasure from "react-use-measure";
2829
import { type MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";

src/room/LobbyView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only
55
Please see LICENSE in the repository root for full details.
66
*/
77

8-
import { type FC, useCallback, useMemo, useState } from "react";
8+
import { type FC, useCallback, useMemo, useState, type JSX } from "react";
99
import { useTranslation } from "react-i18next";
1010
import { type MatrixClient } from "matrix-js-sdk/src/matrix";
1111
import { Button } from "@vector-im/compound-web";

src/room/RoomPage.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ SPDX-License-Identifier: AGPL-3.0-only
55
Please see LICENSE in the repository root for full details.
66
*/
77

8-
import { type FC, useEffect, useState, type ReactNode, useRef } from "react";
8+
import {
9+
type FC,
10+
useEffect,
11+
useState,
12+
type ReactNode,
13+
useRef,
14+
type JSX,
15+
} from "react";
916
import { logger } from "matrix-js-sdk/src/logger";
1017
import { useTranslation } from "react-i18next";
1118
import { CheckIcon } from "@vector-im/compound-design-tokens/assets/web/icons";

src/room/useLoadGroupCall.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export const useLoadGroupCall = (
122122
viaServers: string[],
123123
): GroupCallStatus => {
124124
const [state, setState] = useState<GroupCallStatus>({ kind: "loading" });
125-
const activeRoom = useRef<Room>();
125+
const activeRoom = useRef<Room | undefined>(undefined);
126126
const { t } = useTranslation();
127127

128128
const bannedError = useCallback(

src/settings/RageshakeButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Please see LICENSE in the repository root for full details.
66
*/
77

88
import { useTranslation } from "react-i18next";
9-
import { type FC, useCallback } from "react";
9+
import { type FC, useCallback, type JSX } from "react";
1010
import { Button } from "@vector-im/compound-web";
1111
import { logger } from "matrix-js-sdk/src/logger";
1212

src/useInitial.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { useRef } from "react";
1111
* React hook that returns the value given on the initial render.
1212
*/
1313
export function useInitial<T>(getValue: () => T): T {
14-
const ref = useRef<{ value: T }>();
15-
ref.current ??= { value: getValue() };
14+
const ref = useRef<{ value: T }>({ value: getValue() });
1615
return ref.current.value;
1716
}

src/useReactiveState.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export const useReactiveState = <T>(
2323
updateFn: (prevState?: T) => T,
2424
deps: DependencyList,
2525
): [T, Dispatch<SetStateAction<T>>] => {
26-
const state = useRef<T>();
26+
const state = useRef<T | undefined>(undefined);
2727
if (state.current === undefined) state.current = updateFn();
28-
const prevDeps = useRef<DependencyList>();
28+
const prevDeps = useRef<DependencyList | undefined>(undefined);
2929

3030
// Since we store the state in a ref, we use this counter to force an update
3131
// when someone calls setState

0 commit comments

Comments
 (0)