fix: LazyChatFragment 的依赖忘记修改导致无法使用

This commit is contained in:
CrescentLeaf
2026-01-16 23:45:19 +08:00
parent 25e5650441
commit 326d62a8bd

View File

@@ -1,14 +1,18 @@
import { Chat } from "lingchair-client-protocol" import { Chat } from "lingchair-client-protocol"
import { Await } from "react-router"
import getClient from "../../getClient" import getClient from "../../getClient"
import ChatFragment from "./ChatFragment" import ChatFragment from "./ChatFragment"
import * as React from 'react' import * as React from 'react'
import EffectOnly from "../EffectOnly" import useAsyncEffect from "../../utils/useAsyncEffect"
export default function LazyChatFragment({ chatId, openedInDialog }: { chatId: string, openedInDialog: boolean }) { export default function LazyChatFragment({ chatId, openedInDialog }: { chatId: string, openedInDialog: boolean }) {
return <React.Suspense fallback={<EffectOnly effect={() => {}} deps={[]} />}> const [child, setChild] = React.useState<React.ReactNode>()
<Await const chatInfoPromise = React.useMemo(() => Chat.getByIdOrThrow(getClient(), chatId), [chatId])
resolve={React.useMemo(() => Chat.getByIdOrThrow(getClient(), chatId), [chatId])}
children={(chatInfo: Chat) => <ChatFragment chatInfo={chatInfo} openedInDialog={openedInDialog} />} /> useAsyncEffect(async () => {
setChild(<ChatFragment chatInfo={await chatInfoPromise} openedInDialog={openedInDialog} />)
}, [chatId])
return <React.Suspense fallback={null}>
{child}
</React.Suspense> </React.Suspense>
} }