Skip to content

Commit

Permalink
chore: increase delay to debug #283
Browse files Browse the repository at this point in the history
  • Loading branch information
srizvi committed Apr 28, 2024
1 parent 9c0f5ef commit ccc40e8
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions apps/mai-sc/src/ui/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,45 @@ export function Chat({ id, className, session, missingKeys }: ChatProps) {
const [_, setNewChatId] = useLocalStorage('newChatId', id);

useEffect(() => {
console.log('Before useEffect: Checking session and path');
console.log('SESSION CHECK: Before - Checking session and path');
if (session?.user) {
console.log(
'During useEffect: User is present, checking path and message length',
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
`SESSION CHECK: During - User present, path: ${path}, message length: ${messages.length}`,
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (path === '/chat' && messages.length === 1) {
console.log(
'During useEffect: Path is /chat and only one message, updating path state',
`SESSION CHECK: During - Updating path state to /chat/${id}`,
);
window.history.replaceState({}, '/chat', `/chat/${id}`);
}
}
console.log('After useEffect: Session and path check complete');
console.log('SESSION CHECK: After - Session and path check complete');
}, [id, path, session?.user, messages]);

useEffect(() => {
console.log(
'Before useEffect: Preparing to check AI state messages length with initial delay',
'DELAYED CHECK: Before - Preparing to check AI state messages length with initial delay',
);

async function delayedCheck() {
console.log('During useEffect: Starting delay before checking messages');
await sleep(1000);
console.log(
'During useEffect: Delay complete, now checking messages length',
'DELAYED CHECK: During - Starting 5s delay before checking messages',
);
await sleep(5000);
console.log(
'DELAYED CHECK: During - Delay complete, checking messages length',
);

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
const messagesLength = aiState.messages?.length;
console.log(
`DELAYED CHECK: During - AI state messages length: ${messagesLength}`,
);
if (messagesLength === 2) {
console.log(
'During useEffect: AI state messages length is 2, refreshing router',
'DELAYED CHECK: During - AI state messages length is 2, refreshing router',
);
router.refresh();
}
Expand All @@ -78,17 +84,17 @@ export function Chat({ id, className, session, missingKeys }: ChatProps) {
void delayedCheck();

console.log(
'After useEffect: AI state messages length check and potential refresh complete',
'DELAYED CHECK: After - AI state messages length check and potential refresh complete',
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
}, [aiState.messages, router]);

useEffect(() => {
console.log(
`Before useEffect: Setting new chat ID in local storage to ${id}`,
`CHAT ID: Before - Setting new chat ID in local storage to ${id}`,
);
setNewChatId(id);
console.log(`After useEffect: New chat ID ${id} set in local storage`);
console.log(`CHAT ID: After - New chat ID ${id} set in local storage`);
}, [id, setNewChatId]);

useEffect(() => {
Expand Down

0 comments on commit ccc40e8

Please sign in to comment.