Skip to content

Fix MessageRow parsing errors and defer useAsync initial execution#13

Merged
CheFu-code merged 1 commit into
mainfrom
codex/find-and-fix-repo-bug
Jun 20, 2026
Merged

Fix MessageRow parsing errors and defer useAsync initial execution#13
CheFu-code merged 1 commit into
mainfrom
codex/find-and-fix-repo-bug

Conversation

@CheFu-code

@CheFu-code CheFu-code commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Motivation

  • The MessageRow module contained duplicated and malformed imports/props causing TypeScript parsing errors and preventing the app from building.
  • The useAsync hook triggered a React lint rule by calling state-updating code synchronously inside an effect, which can cause cascading renders.

Description

  • Removed duplicated and malformed imports and props from src/components/MessageRow.tsx and restored proper ContactPreview and MailThread typings.
  • Replaced the inline React.KeyboardEvent reference with an imported KeyboardEvent type and removed an unused getMessageFolderLabel import in MessageRow.
  • Updated src/hooks/useAsync.ts to defer the initial execute() call using void Promise.resolve().then(execute) to avoid synchronous setState inside useEffect.

Testing

  • Ran npm run typecheck which completed successfully.
  • Ran npm run lint which completed successfully.
  • Ran npm run build which failed due to Next.js being unable to fetch Geist and Geist Mono from Google Fonts in this environment, which is unrelated to the code changes.

Codex Task

Summary by CodeRabbit

  • Refactor
    • Improved TypeScript type definitions and cleaned up import organization in message components for enhanced code maintainability
    • Updated asynchronous hook initialization to defer execution when immediate mode is enabled, preventing potential timing-related issues during component mounting

@vercel

vercel Bot commented Jun 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flow Ready Ready Preview, Comment Jun 20, 2026 7:56am

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

MessageRow.tsx converts several imports to type-only form, removes unused imports, and narrows the onKeyDown prop's event parameter type from React.KeyboardEvent to the directly imported KeyboardEvent. useAsync.ts changes the immediate-mode initial execution from a synchronous call to a microtask-deferred call via Promise.resolve().then(execute).

Changes

Import Cleanup and Async Deferral

Layer / File(s) Summary
MessageRow import cleanup and onKeyDown type narrowing
src/components/MessageRow.tsx
Import section is rewritten to use import type for React event types and model types, removes getMessageFolderLabel and duplicate imports, and the onKeyDown prop event parameter type is updated from React.KeyboardEvent<HTMLDivElement> to the locally imported KeyboardEvent<HTMLDivElement>.
useAsync immediate execution deferred to microtask
src/hooks/useAsync.ts
In the useEffect for immediate === true, the initial execute() call is replaced with void Promise.resolve().then(execute), deferring execution to a microtask instead of running synchronously.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~4 minutes

Possibly related PRs

  • CheFu-code/flow#12: Modifies the same src/components/MessageRow.tsx onKeyDown typing and src/hooks/useAsync.ts immediate execution path.

Poem

🐇 A type here, a microtask there,
Imports trimmed with rabbit-like care.
No React. prefix, just KeyboardEvent plain,
And execute waits for a promise's refrain.
Cleaner code hops through the warren again! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes both main changes: fixing MessageRow parsing errors and deferring useAsync initial execution.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/find-and-fix-repo-bug

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with 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.

Inline comments:
In `@src/hooks/useAsync.ts`:
- 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.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c1342f86-d0b9-450a-87e3-abf9367f89ab

📥 Commits

Reviewing files that changed from the base of the PR and between 82f1163 and 8a85f40.

📒 Files selected for processing (2)
  • src/components/MessageRow.tsx
  • src/hooks/useAsync.ts

Comment thread src/hooks/useAsync.ts

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.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 1 file(s) based on 1 unresolved review comment.

Files modified:

  • src/hooks/useAsync.ts

Commit: 687b68d9fbeb90a66270e12a0352714dc8e456db

The changes have been pushed to the codex/find-and-fix-repo-bug branch.

Time taken: 7m 21s

@CheFu-code
CheFu-code merged commit 21c0e1e into main Jun 20, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant