Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions src/components/MessageRow.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
'use client';

import { Star } from 'lucide-react';
import type { MouseEvent } from 'react';
import type { KeyboardEvent, MouseEvent } from 'react';
import { memo } from 'react';
import { ContactHoverCard } from '@/components/flow-console/ContactHoverCard';
import { formatListDate, getMessageFolderLabel, sentTrackingKind, sentTrackingLabel } from '@/lib/flow-console/format';
import { formatListDate, sentTrackingKind, sentTrackingLabel } from '@/lib/flow-console/format';
import { contactFromMessage } from '@/lib/flow-console/mail';
import type { MailThread } from '@/lib/flow-console/types';
import styles from './FlowConsole.module.css';

interface MessageRowProps {
thread: MailThread;
isSelected: boolean;
onSelect: (threadId: string) => void;
onToggleSelect: (threadId: string) => void;
onToggleStarred: (event: MouseEvent, messageId: string) => void;
import { Star } from 'lucide-react';
import type { MouseEvent } from 'react';
import { memo } from 'react';
import { ContactHoverCard } from '`@/components/flow-console/ContactHoverCard`';
import type { ContactPreview } from '`@/lib/flow-console/types`';
import { formatListDate, getMessageFolderLabel, sentTrackingKind, sentTrackingLabel } from '`@/lib/flow-console/format`';
import { contactFromMessage } from '`@/lib/flow-console/mail`';
import type { MailThread } from '`@/lib/flow-console/types`';
import type { ContactPreview, MailThread } from '@/lib/flow-console/types';
import styles from './FlowConsole.module.css';

interface MessageRowProps {
Expand All @@ -33,8 +17,7 @@ interface MessageRowProps {
onToggleStarred: (event: MouseEvent, messageId: string) => void;
onOpenCompose: (contact: ContactPreview) => void;
onShowStatus: (tool: string, contact: ContactPreview) => void;
onKeyDown: (event: React.KeyboardEvent<HTMLDivElement>, threadId: string) => void;
}
onKeyDown: (event: KeyboardEvent<HTMLDivElement>, threadId: string) => void;
}

export const MessageRow = memo(function MessageRow({
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function useAsync<T>(
mountedRef.current = true;

if (immediate) {
execute();
void Promise.resolve().then(execute);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Guard deferred execution against unmount before execute runs.

Line 43 schedules execute in a microtask, but execute starts with an unconditional setState. If unmount happens before that microtask runs, this still attempts a state update after unmount. Guard before invoking execute.

Suggested patch
   if (immediate) {
-    void Promise.resolve().then(execute);
+    void Promise.resolve().then(() => {
+      if (mountedRef.current) {
+        void execute();
+      }
+    });
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
void Promise.resolve().then(execute);
if (immediate) {
void Promise.resolve().then(() => {
if (mountedRef.current) {
void execute();
}
});
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useAsync.ts` at line 43, The `execute` function is scheduled in a
microtask via Promise.resolve().then() on line 43, but if the component unmounts
before the microtask executes, it will still run and trigger a state update
after unmount. Add a guard condition that checks whether the component is still
mounted before the execute callback runs in the Promise chain. You should use a
mounted ref or similar mechanism to track component lifecycle and only invoke
execute if the component is still mounted.

}

return () => {
Expand Down
Loading