Skip to content

Commit 8fe20c9

Browse files
committed
feat: make the source compatible with React v19
1 parent 0d946b4 commit 8fe20c9

26 files changed

+91
-74
lines changed

.releaserc.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@
7272
}
7373
],
7474
[
75-
"@semantic-release/exec", {
76-
"prepareCmd": "NEXT_VERSION=${nextRelease.version} npm run build"
77-
}],
75+
"@semantic-release/exec",
76+
{
77+
"prepareCmd": "NEXT_VERSION=${nextRelease.version} npm run build"
78+
}
79+
],
7880
[
7981
"@semantic-release/changelog",
8082
{

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@
202202
"@types/lodash.throttle": "^4.1.7",
203203
"@types/lodash.uniqby": "^4.7.7",
204204
"@types/moment": "^2.13.0",
205-
"@types/react": "^18.2.55",
206-
"@types/react-dom": "^18.2.19",
205+
"@types/react": "^19.0.7",
206+
"@types/react-dom": "^19.0.3",
207207
"@types/react-image-gallery": "^1.2.4",
208-
"@types/react-is": "^18.2.4",
208+
"@types/react-is": "^19.0.0",
209209
"@types/textarea-caret": "3.0.0",
210210
"@types/uuid": "^8.3.0",
211211
"@typescript-eslint/eslint-plugin": "5.62.0",
@@ -253,8 +253,8 @@
253253
"lint-staged": "^15.2.1",
254254
"moment-timezone": "^0.5.43",
255255
"prettier": "^2.2.0",
256-
"react": "^18.1.0",
257-
"react-dom": "^18.1.0",
256+
"react": "^19.0.0",
257+
"react-dom": "^19.0.0",
258258
"react-test-renderer": "^18.1.0",
259259
"semantic-release": "^19.0.5",
260260
"stream-chat": "^8.47.1",

src/components/Attachment/components/WaveProgressBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const WaveProgressBar = ({
4141
barWidth: number;
4242
gap: number;
4343
}>();
44-
const lastRootWidth = useRef<number>();
44+
const lastRootWidth = useRef<number>(undefined);
4545

4646
const handleDragStart: PointerEventHandler<HTMLDivElement> = (e) => {
4747
e.preventDefault();

src/components/Attachment/hooks/useAudioController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const useAudioController = ({
3535
const [canPlayRecord, setCanPlayRecord] = useState(true);
3636
const [secondsElapsed, setSecondsElapsed] = useState(0);
3737
const [playbackRateIndex, setPlaybackRateIndex] = useState<number>(0);
38-
const playTimeout = useRef<ReturnType<typeof setTimeout>>();
38+
const playTimeout = useRef<ReturnType<typeof setTimeout>>(undefined);
3939
const audioRef = useRef<HTMLAudioElement | null>(null);
4040

4141
const registerError = useCallback(

src/components/Channel/Channel.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
import { nanoid } from 'nanoid';
3434
import clsx from 'clsx';
3535

36-
import { channelReducer, ChannelStateReducer, initialState } from './channelState';
36+
import { initialState, makeChannelReducer } from './channelState';
3737
import { useCreateChannelStateContext } from './hooks/useCreateChannelStateContext';
3838
import { useCreateTypingContext } from './hooks/useCreateTypingContext';
3939
import { useEditMessageHandler } from './hooks/useEditMessageHandler';
@@ -378,7 +378,9 @@ const ChannelInner = <
378378

379379
const notificationTimeouts = useRef<Array<NodeJS.Timeout>>([]);
380380

381-
const [state, dispatch] = useReducer<ChannelStateReducer<StreamChatGenerics>>(
381+
const channelReducer = useMemo(() => makeChannelReducer<StreamChatGenerics>(), []);
382+
383+
const [state, dispatch] = useReducer(
382384
channelReducer,
383385
// channel.initialized === false if client.channel().query() was not called, e.g. ChannelList is not used
384386
// => Channel will call channel.watch() in useLayoutEffect => state.loading is used to signal the watch() call state
@@ -392,7 +394,7 @@ const ChannelInner = <
392394
const isMounted = useIsMounted();
393395

394396
const originalTitle = useRef('');
395-
const lastRead = useRef<Date | undefined>();
397+
const lastRead = useRef<Date | undefined>(undefined);
396398
const online = useRef(true);
397399

398400
const channelCapabilitiesArray = channel.data?.own_capabilities as string[];

src/components/Channel/channelState.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { Reducer } from 'react';
21
import type { Channel, MessageResponse, ChannelState as StreamChannelState } from 'stream-chat';
32

43
import type { ChannelState, StreamMessage } from '../../context/ChannelStateContext';
@@ -85,13 +84,9 @@ export type ChannelStateReducerAction<
8584
type: 'jumpToLatestMessage';
8685
};
8786

88-
export type ChannelStateReducer<
87+
export const makeChannelReducer = <
8988
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
90-
> = Reducer<ChannelState<StreamChatGenerics>, ChannelStateReducerAction<StreamChatGenerics>>;
91-
92-
export const channelReducer = <
93-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
94-
>(
89+
>() => (
9590
state: ChannelState<StreamChatGenerics>,
9691
action: ChannelStateReducerAction<StreamChatGenerics>,
9792
) => {

src/components/ChannelList/ChannelList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ const UnMemoizedChannelList = <SCG extends DefaultStreamChatGenerics = DefaultSt
204204
useImageFlagEmojisOnWindows,
205205
} = useChatContext<SCG>('ChannelList');
206206

207-
const channelListRef = useRef<HTMLDivElement>(null);
207+
const channelListRef = useRef<HTMLDivElement | null>(null);
208208
const [channelUpdateCount, setChannelUpdateCount] = useState(0);
209209
const [searchActive, setSearchActive] = useState(false);
210210
/**
@@ -336,7 +336,7 @@ const UnMemoizedChannelList = <SCG extends DefaultStreamChatGenerics = DefaultSt
336336
watchers,
337337
};
338338

339-
return <ChannelPreview {...previewProps} />;
339+
return <ChannelPreview<SCG> {...previewProps} />;
340340
};
341341

342342
const baseClass = 'str-chat__channel-list';

src/components/ChannelList/hooks/useChannelListShape.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,9 @@ export const usePrepareShapeHandlers = <SCG extends ExtendableGenerics>({
478478
}: UseDefaultHandleChannelListShapeParameters<SCG>) => {
479479
const defaults = useChannelListShapeDefaults<SCG>();
480480

481-
const defaultHandleChannelListShapeRef = useRef<(e: Event<SCG>) => void>();
481+
const defaultHandleChannelListShapeRef = useRef<(e: Event<SCG>) => void>(undefined);
482482

483-
const customHandleChannelListShapeRef = useRef<(e: Event<SCG>) => void>();
483+
const customHandleChannelListShapeRef = useRef<(e: Event<SCG>) => void>(undefined);
484484

485485
customHandleChannelListShapeRef.current = (event: Event<SCG>) => {
486486
// @ts-expect-error can't use ReturnType<typeof useChannelListShapeDefaults<SCG>> until we upgrade prettier to at least v2.7.0

src/components/ChannelList/hooks/useMobileNavigation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect } from 'react';
22

33
export const useMobileNavigation = (
4-
channelListRef: React.RefObject<HTMLDivElement>,
4+
channelListRef: React.RefObject<HTMLDivElement | null>,
55
navOpen: boolean,
66
closeMobileNav?: () => void,
77
) => {

src/components/ChannelList/hooks/usePaginatedChannels.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const usePaginatedChannels = <
4848
} = useChatContext('usePaginatedChannels');
4949
const [channels, setChannels] = useState<Array<Channel<StreamChatGenerics>>>([]);
5050
const [hasNextPage, setHasNextPage] = useState(true);
51-
const lastRecoveryTimestamp = useRef<number | undefined>();
51+
const lastRecoveryTimestamp = useRef<number | undefined>(undefined);
5252

5353
const recoveryThrottleInterval =
5454
recoveryThrottleIntervalMs < MIN_RECOVER_LOADED_CHANNELS_THROTTLE_INTERVAL_IN_MS

0 commit comments

Comments
 (0)