Skip to content

fix(ui): keep comment text when a post or edit fails#320

Merged
martian56 merged 2 commits into
Devlaner:mainfrom
cavidelizade:fix/comment-editor-dataloss
Jul 16, 2026
Merged

fix(ui): keep comment text when a post or edit fails#320
martian56 merged 2 commits into
Devlaner:mainfrom
cavidelizade:fix/comment-editor-dataloss

Conversation

@cavidelizade

@cavidelizade cavidelizade commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

CommentEditor cleared the editor synchronously right after firing onSubmit, so a failed comment (offline, 5xx, or the EXTERNAL-comment permission error) was silently lost — the parent showed an error toast but the typed text was already gone.

Linked issues

Closes #315

Type of change

  • Bug fix (fix:)

Surface

  • UI (apps/web/)

What changed

  • onSubmit now reports success: it may return/resolve to false (or throw) to signal failure. CommentEditor.handleSubmit awaits it and only calls clearContent() when the submit actually succeeded.
  • postComment / updateComment on the work-item page return true/false accordingly (they already caught their own errors and showed a message — they just didn't tell the editor).

Why this approach

The parent deliberately swallows the error to render its own message, so the promise resolved even on failure and the editor couldn't tell success from failure. Rather than make the parent rethrow (which would double-handle the error), the handler now returns a success flag — the least surprising contract for a controlled editor.

Test plan

  • npm run typecheck + npm run lint (with the i18n gate) pass
  • Manual: post a comment with the API stopped → error shows and the text stays in the composer; retry after the API is back → posts and clears. Same for inline edit.

AI assistance

  • AI tools were used — tool(s): Claude Code (Opus 4.8) — commits carry a Co-Authored-By: trailer

Summary by CodeRabbit

  • Bug Fixes
    • Comment drafts are no longer cleared when posting or editing fails.
    • Failed comment submissions now display an error while preserving entered content for retry.
    • Comment posting and editing states reset reliably after completion, including failed requests.
    • Empty comments and unavailable workspace details are handled without losing the draft.

CommentEditor cleared the editor synchronously right after firing onSubmit,
so a failed comment (offline, 5xx, EXTERNAL-comment permission error) was
silently lost — the parent showed an error but the typed text was already gone.

onSubmit now reports success: it may return/resolve to false (or throw) to
signal failure, and the editor only clears when the submit actually succeeds.
postComment/updateComment on the work-item page return true/false accordingly.

Closes Devlaner#315

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cavidelizade cavidelizade requested a review from a team as a code owner July 16, 2026 09:57

@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.

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 `@apps/web/src/components/work-item/CommentEditor.tsx`:
- Around line 116-130: Update handleSubmit after the awaited onSubmit call and
error handling to check editor.isDestroyed before calling
editor.commands.clearContent() or updating editor-related state. If the editor
has been destroyed, return without interacting with it; preserve the existing
successful-submit behavior otherwise.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fc89f20d-1d30-4660-9f05-7f1dfeacea7e

📥 Commits

Reviewing files that changed from the base of the PR and between a81f6a3 and d69422e.

📒 Files selected for processing (2)
  • apps/web/src/components/work-item/CommentEditor.tsx
  • apps/web/src/pages/IssueDetailPage.tsx

Comment thread apps/web/src/components/work-item/CommentEditor.tsx
Since onSubmit is awaited, the editor can be torn down (parent unmounts or
cancels the edit) before the submit resolves; clearing a destroyed TipTap
editor throws. Bail out when editor.isDestroyed before clearContent.

Addresses CodeRabbit review on Devlaner#315.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Devlaner Devlaner deleted a comment from coderabbitai Bot Jul 16, 2026
@martian56 martian56 merged commit 61bc903 into Devlaner:main Jul 16, 2026
2 checks passed
@martian56 martian56 self-assigned this Jul 16, 2026
@cavidelizade

Copy link
Copy Markdown
Contributor Author

@martian56 small but annoying bug (#315): posting a comment cleared the editor before the request finished, so a failed post lost whatever you typed. Now it only clears on success. CodeRabbit flagged an edge case (clearing a torn-down editor) which I've fixed and resolved. Green and no open threads — good to go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comment editor clears typed text before the submit resolves (data loss on failure)

2 participants