Skip to content

Commit 0f800bc

Browse files
committed
fix(timeline): add isReadyRef, fix handleEdit refs, fix inline import() types
- RoomTimeline.tsx: define isReadyRef to safely read isReady inside setTimeout closures; rename handleEditCallback → handleEdit (shorthand) - ThreadDrawer.tsx: rename handleEditCallback → handleEdit - ThreadBrowser.tsx: replace forbidden inline import() type annotations with top-level HTMLReactParserOptions and LinkifyOpts imports; html-react- parser v4 exports HTMLReactParserOptions (not Options)
1 parent 5365f80 commit 0f800bc

4 files changed

Lines changed: 24 additions & 67 deletions

File tree

docs/TIMELINE_FIXES.md

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/app/features/room/RoomTimeline.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ export function RoomTimeline({
244244
const currentRoomIdRef = useRef(room.roomId);
245245

246246
const [isReady, setIsReady] = useState(false);
247+
const isReadyRef = useRef(isReady);
248+
isReadyRef.current = isReady;
247249

248250
if (currentRoomIdRef.current !== room.roomId) {
249251
hasInitialScrolledRef.current = false;
@@ -588,7 +590,7 @@ export function RoomTimeline({
588590
setReplyDraft: setReplyDraft as unknown as (draft: unknown) => void,
589591
openThreadId,
590592
setOpenThread: setOpenThread as unknown as (threadId: string | undefined) => void,
591-
handleEdit: handleEditCallback,
593+
handleEdit,
592594
handleOpenEvent: (id) => {
593595
const anchorId = unwrapRelationJumpTarget(room, id);
594596
let evtTimeline = getEventTimeline(room, anchorId);
@@ -1137,18 +1139,29 @@ export function RoomTimeline({
11371139
}}
11381140
>
11391141
<MessageBase space={messageSpacing}>
1140-
{messageLayout === MessageLayout.Compact ? <CompactPlaceholder /> : <DefaultPlaceholder />}
1142+
{messageLayout === MessageLayout.Compact ? (
1143+
<CompactPlaceholder />
1144+
) : (
1145+
<DefaultPlaceholder />
1146+
)}
11411147
</MessageBase>
11421148
<MessageBase space={messageSpacing}>
1143-
{messageLayout === MessageLayout.Compact ? <CompactPlaceholder /> : <DefaultPlaceholder />}
1149+
{messageLayout === MessageLayout.Compact ? (
1150+
<CompactPlaceholder />
1151+
) : (
1152+
<DefaultPlaceholder />
1153+
)}
11441154
</MessageBase>
11451155
<MessageBase space={messageSpacing}>
1146-
{messageLayout === MessageLayout.Compact ? <CompactPlaceholder /> : <DefaultPlaceholder />}
1156+
{messageLayout === MessageLayout.Compact ? (
1157+
<CompactPlaceholder />
1158+
) : (
1159+
<DefaultPlaceholder />
1160+
)}
11471161
</MessageBase>
11481162
</div>
11491163
)}
11501164

1151-
11521165
{(!atBottomState || !timelineSync.liveTimelineLinked) && isReady && (
11531166
<TimelineFloat position="Bottom">
11541167
<Chip

src/app/features/room/ThreadBrowser.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
import type { EventTimelineSet, MatrixEvent, Room, Thread } from '$types/matrix-sdk';
1919
import { NotificationCountType, RoomEvent, ThreadEvent } from '$types/matrix-sdk';
2020
import { useAtomValue } from 'jotai';
21+
import type { HTMLReactParserOptions } from 'html-react-parser';
22+
import type { Opts as LinkifyOpts } from 'linkifyjs';
2123
import { useMatrixClient } from '$hooks/useMatrixClient';
2224
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
2325
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
@@ -74,7 +76,7 @@ function ThreadPreview({ room, thread, onClick, onJump }: ThreadPreviewProps) {
7476
const mentionClickHandler = useMentionClickHandler(room.roomId);
7577
const spoilerClickHandler = useSpoilerClickHandler();
7678

77-
const linkifyOpts = useMemo<import('linkifyjs').Opts>(
79+
const linkifyOpts = useMemo<LinkifyOpts>(
7880
() => ({
7981
...LINKIFY_OPTS,
8082
render: factoryRenderLinkifyWithMention(
@@ -93,7 +95,7 @@ function ThreadPreview({ room, thread, onClick, onJump }: ThreadPreviewProps) {
9395
[mx, room.roomId, nicknames, mentionClickHandler, settingsLinkBaseUrl]
9496
);
9597

96-
const htmlReactParserOptions = useMemo<import('html-react-parser').Options>(
98+
const htmlReactParserOptions = useMemo<HTMLReactParserOptions>(
9799
() =>
98100
getReactCustomHtmlParser(mx, room.roomId, {
99101
settingsLinkBaseUrl,

src/app/features/room/ThreadDrawer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ export function ThreadDrawer({ room, threadRootId, onClose, overlay }: ThreadDra
618618
);
619619
const ownId = ownReply?.id;
620620
if (ownId) {
621-
handleEditCallback(ownId);
621+
handleEdit(ownId);
622622
const el = drawerRef.current;
623623
if (el) {
624624
el.querySelector(`[data-message-id="${ownId}"]`)?.scrollIntoView({
@@ -627,7 +627,7 @@ export function ThreadDrawer({ room, threadRootId, onClose, overlay }: ThreadDra
627627
});
628628
}
629629
}
630-
}, [mx, threadRootId, handleEditCallback]);
630+
}, [mx, threadRootId, handleEdit]);
631631

632632
const handleResend = useCallback(
633633
(event: MatrixEvent) => {

0 commit comments

Comments
 (0)