Skip to content

[_]: fix: update draft handling in compose message component and hooks#70

Merged
jzunigax2 merged 4 commits into
masterfrom
fix/draft-handling
Jul 13, 2026
Merged

[_]: fix: update draft handling in compose message component and hooks#70
jzunigax2 merged 4 commits into
masterfrom
fix/draft-handling

Conversation

@jzunigax2

Copy link
Copy Markdown
Contributor
  • Introduced flushPendingDraftSave to manage draft saving more effectively.
  • Replaced draftId with resolveDraftId in useComposeSend for better draft resolution.
  • Enhanced saveDraft logic to prevent duplicate saves during concurrent operations.
  • Updated tests to reflect changes in draft handling and ensure correct functionality.

- Introduced `flushPendingDraftSave` to manage draft saving more effectively.
- Replaced `draftId` with `resolveDraftId` in `useComposeSend` for better draft resolution.
- Enhanced `saveDraft` logic to prevent duplicate saves during concurrent operations.
- Updated tests to reflect changes in draft handling and ensure correct functionality.
@jzunigax2 jzunigax2 requested a review from xabg2 as a code owner July 8, 2026 23:48
@jzunigax2 jzunigax2 added the enhancement New feature or request label Jul 8, 2026
@jzunigax2 jzunigax2 self-assigned this Jul 8, 2026
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 44d376fa-76c1-4848-b7fa-79f694c9b2cc

📥 Commits

Reviewing files that changed from the base of the PR and between 1148612 and 38cc752.

📒 Files selected for processing (2)
  • src/components/compose-message/hooks/useDraftMessage.test.ts
  • src/components/compose-message/hooks/useDraftMessage.ts

📝 Walkthrough

Walkthrough

Draft autosave now queues concurrent saves and exposes asynchronous draft ID resolution. Sending awaits that resolver, and the compose dialog passes it through. Tests cover pending saves, autosave re-arming, resolved draft IDs, and new-email sends.

Changes

Draft save coordination and send integration

Layer / File(s) Summary
Draft save coordination
src/components/compose-message/hooks/useDraftMessage.ts
Queues saves, refactors autosave scheduling, waits for pending saves, and returns resolveDraftId.
Draft save and autosave tests
src/components/compose-message/hooks/useDraftMessage.test.ts
Updates editor mocks and tests concurrent saves, pending draft resolution, discard synchronization, and editor-triggered autosave scheduling.
Async draft resolution in send
src/components/compose-message/hooks/useComposeSend.ts, src/components/compose-message/hooks/useComposeSend.test.ts
Replaces the static draft ID with an awaited resolver and verifies resolved and absent draft IDs.
Compose message wiring
src/components/compose-message/index.tsx
Passes resolveDraftId from useDraftMessage into useComposeSend.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: xabg2, larryrider

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: draft handling updates in the compose message hooks and component.
Description check ✅ Passed The description matches the changeset and mentions the updated draft-saving and resolveDraftId behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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 fix/draft-handling

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.

Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.

👉 Steps to fix this

Actionable comments posted: 2

🤖 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/components/compose-message/hooks/useComposeSend.test.ts`:
- Around line 314-315: The affected test descriptions in useComposeSend.test
should be rewritten to follow the “When…then…” style without naming
implementation details like sendEmail or draftId. Update the descriptions for
the related tests in the useComposeSend test suite to describe the behavior in
user-facing terms, while keeping the assertions and setup unchanged.

In `@src/components/compose-message/hooks/useDraftMessage.ts`:
- Around line 130-164: Extract the repeated autosave timer cleanup in
useDraftMessage into a shared helper (for example a clearAutosaveTimer-style
function) and reuse it in saveDraft, flushPendingDraftSave, clearDraftRef, and
scheduleAutosave. Make sure the helper still nulls timerRef.current after
clearTimeout, and update each useCallback’s dependency array to include the new
helper so the teardown logic stays consistent and DRY.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 680672d6-f875-4472-8563-a33674b6e4d6

📥 Commits

Reviewing files that changed from the base of the PR and between a01ab37 and 5f5c841.

📒 Files selected for processing (5)
  • src/components/compose-message/hooks/useComposeSend.test.ts
  • src/components/compose-message/hooks/useComposeSend.ts
  • src/components/compose-message/hooks/useDraftMessage.test.ts
  • src/components/compose-message/hooks/useDraftMessage.ts
  • src/components/compose-message/index.tsx

Comment thread src/components/compose-message/hooks/useComposeSend.test.ts Outdated
Comment thread src/components/compose-message/hooks/useDraftMessage.ts Outdated
toRecipients,
inReplyTo: inReplyItemId,
draftId: draftId ?? undefined,
resolveDraftId: flushPendingDraftSave,

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.

Would be better resolvePendingDrafts or smth like that. What do you think?

… clarity

- Updated the draft handling logic in the ComposeMessage component and related hooks.
- Replaced `flushPendingDraftSave` with `resolveDraftId` to better reflect its purpose.
- Adjusted tests to align with the new draft resolution approach and ensure accurate functionality.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 9, 2026

Copy link
Copy Markdown

Deploying mail-web with  Cloudflare Pages  Cloudflare Pages

Latest commit: 38cc752
Status: ✅  Deploy successful!
Preview URL: https://fe8f0220.mail-web-ea0.pages.dev
Branch Preview URL: https://fix-draft-handling.mail-web-ea0.pages.dev

View logs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.

Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.

👉 Steps to fix this

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/components/compose-message/hooks/useDraftMessage.ts`:
- Around line 167-170: Cancel the autosave timer in handleDraftDiscard before
the draft deletion request is awaited, so a pending autosave cannot race with
discardDraft and call updateDraft on the same draft; update useDraftMessage to
invoke clearAutosaveTimer() at the start of handleDraftDiscard, before
discardDraft({ draftId: draftIdRef.current }).unwrap(), and keep the guard on
draftIdRef.current intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 18d0b740-5dfb-44bf-8e7c-7f4785c4b5a6

📥 Commits

Reviewing files that changed from the base of the PR and between 5f5c841 and d319bea.

📒 Files selected for processing (4)
  • src/components/compose-message/hooks/useComposeSend.test.ts
  • src/components/compose-message/hooks/useDraftMessage.test.ts
  • src/components/compose-message/hooks/useDraftMessage.ts
  • src/components/compose-message/index.tsx

Comment thread src/components/compose-message/hooks/useDraftMessage.ts Outdated
- Added clearAutosaveTimer to the handleDraftDiscard function to ensure proper cleanup when discarding drafts.
- Updated dependencies in the useCallback hook to reflect the new logic.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.

Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.

👉 Steps to fix this

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/components/compose-message/hooks/useDraftMessage.ts`:
- Around line 167-171: Update handleDraftDiscard to await pendingSaveRef.current
immediately after clearAutosaveTimer(), before checking draftIdRef.current,
mirroring resolveDraftId(). Then discard the resolved draft ID so an in-flight
createDraft() completes before the discard request.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6db74d60-8ab4-46b4-942e-a9302ac4c86a

📥 Commits

Reviewing files that changed from the base of the PR and between d319bea and 1148612.

📒 Files selected for processing (1)
  • src/components/compose-message/hooks/useDraftMessage.ts

Comment thread src/components/compose-message/hooks/useDraftMessage.ts Outdated
- Implemented a test to verify that discarding a draft while a save is in progress waits for the save to complete before discarding.
- Updated the `handleDraftDiscard` function to resolve the draft ID before attempting to discard, ensuring proper draft management.
@sonarqubecloud

Copy link
Copy Markdown

@jzunigax2 jzunigax2 merged commit d530e5e into master Jul 13, 2026
6 checks passed
@jzunigax2 jzunigax2 deleted the fix/draft-handling branch July 13, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants