fix(fe): crash 'reading channel_id' + recharts width/height warnings
Build & Deploy (Nix) / build-and-deploy (backend) (push) Successful in 2m14s
Build & Deploy (Nix) / build-and-deploy (discord-gateway) (push) Successful in 2m53s
Build & Deploy (Nix) / build-and-deploy (proxy) (push) Successful in 3m15s
Build & Deploy (Nix) / build-and-deploy (backend) (push) Successful in 2m14s
Build & Deploy (Nix) / build-and-deploy (discord-gateway) (push) Successful in 2m53s
Build & Deploy (Nix) / build-and-deploy (proxy) (push) Successful in 3m15s
- useMessageDetail: guard attachments fetcher — revalidate bisa race detail load, detail.data undefined saat fetcher jalan -> TypeError 'Cannot read properties of undefined (reading channel_id)' yang bikin halaman /messages mati (Next error boundary). Sekarang fetcher balikin [] kalau channel_id belum ada; hapus non-null assertion. Diverifikasi: /messages sebelumnya crash, sekarang render dengan data asli (list, verdict, confidence, sticker, emoji). - ResponsiveContainer (recharts 3.8): initialDimension -1 di render pertama -> warning 'width(-1) and height(-1)'. Pakai height numerik tetap (192/160/48) + minWidth/minHeight 0 -> calculatedHeight >0, warning hilang; width tetap responsif via ResizeObserver. Chart baru dirender setelah mount (useMounted) biar container punya ukuran. Diverifikasi console: 0 warning, 0 error di dashboard & voice.
This commit is contained in:
@@ -126,14 +126,17 @@ export function useReview(channelId?: string) {
|
||||
|
||||
export function useMessageDetail(id: string | null) {
|
||||
const detail = useSWR<MessageRecord>(id ? msgKeys.detail(id) : null, () =>
|
||||
messagesApi.getDetail(id!),
|
||||
messagesApi.getDetail(id ?? ""),
|
||||
);
|
||||
const channelId = id ? detail.data?.channel_id : undefined;
|
||||
const attachments = useSWR<AttachmentRecord[]>(
|
||||
id && detail.data?.channel_id
|
||||
? [...msgKeys.detail(id), "attachments"]
|
||||
: null,
|
||||
channelId ? [...msgKeys.detail(id ?? ""), "attachments"] : null,
|
||||
async () => {
|
||||
const res = await messagesApi.getAttachments(detail.data!.channel_id, 10);
|
||||
// Guard: only fetch when we actually have a channel id — a revalidate
|
||||
// can race the detail load and see detail.data === undefined.
|
||||
const cid = detail.data?.channel_id;
|
||||
if (!cid) return [];
|
||||
const res = await messagesApi.getAttachments(cid, 10);
|
||||
return res.data;
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user