Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a2402ce

Browse files
authored
Merge pull request #10 from ayobro1/copilot/fix-chat-loading-animation
Defer loading spinner to eliminate flash on chat open
2 parents 8772052 + cbbade0 commit a2402ce

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/components/MessageArea.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,11 @@ export default function MessageArea({
214214
useEffect(() => {
215215
if (!channelId) return;
216216

217-
setIsLoading(true);
218217
setReplyTo(null); // Clear reply when switching channels
219218

219+
// Only show loading spinner if fetch takes longer than 300ms to avoid flash
220+
const loadingTimer = setTimeout(() => setIsLoading(true), 300);
221+
220222
const fetchMessages = async () => {
221223
try {
222224
const res = await fetch(`/api/messages?channelId=${channelId}`);
@@ -234,6 +236,7 @@ export default function MessageArea({
234236
console.error("Failed to fetch messages:", error);
235237
setMessages([]);
236238
} finally {
239+
clearTimeout(loadingTimer);
237240
setIsLoading(false);
238241
}
239242
};
@@ -284,6 +287,7 @@ export default function MessageArea({
284287
};
285288

286289
return () => {
290+
clearTimeout(loadingTimer);
287291
eventSource.close();
288292
setTypingUsers(new Map());
289293
};

0 commit comments

Comments
 (0)