Harden comment submission against missing required fields - #1770
Conversation
Clicking Reply/Update with an empty box called buildCommentOp with an empty body, which threw "[SDK][buildCommentOp] Missing required parameters" straight into a toast (ECENCY-NEXT-1GQ3). Ctrl/Cmd+Enter already checked text.trim(); the button did not, so nothing stopped the click. Disable the button and early-return in submit. The composer is shared, so this covers the entry page reply box, discussion items, entry edit, curation desk and the deck viewer in one place, and the error toast never appears at all. Mirror create-reply's empty-body guard in update-reply as well. Editing still reached buildCommentOp unguarded. Whitespace-only text is the worse case there: it passes the !body check and broadcasts a blank edit for real.
|
Pushed Reproduced the reported path from the event ( Two gaps this commit closes:
The actual fix is one level up: disable the submit button and early-return in Added two specs pinning it ( The |
Follow-up on review feedback.
.trim() strips Unicode whitespace but not format characters, so a body made only
of U+200B, ZWNJ, ZWJ or a word joiner survived every guard in this PR and got
broadcast as a comment that renders as nothing. isBlankBody() strips \p{Cf}
before trimming. It is now the single rule behind the composer gate, create-reply,
update-reply, the waves form and the decks thread form. Those last two gated on
!text alone, so whitespace-only waves and threads could still be posted.
The SDK had the same check twice with different semantics. buildCommentOp is the
one point create, update and cross-post all pass through, so the missing-field
list moved there and the copy in useComment is gone. That copy only ever covered
create, and it rejected an empty parentPermlink where the builder allows one.
The user-facing message now goes through i18next as comment.empty-body. Dropped
the em dash from the parent permlink error while there.
Tests: is-blank-body covers the zero-width cases plus a ZWJ emoji that must not
read as blank, and buildCommentOp names each missing field.
|
Second round, from review feedback. Pushed Confirmed and fixed
One claim I could not reproduce: the Pin calls On "fix it once at Verification: |
This PR addresses the issue where users encountered an
[SDK][buildCommentOp] Missing required parameterserror when attempting to submit comments or replies, particularly on deeply nested reply pages or with empty comment bodies.Root Cause:
The
buildCommentOpfunction in the@ecency/sdkwas being called with incompleteCommentPayloaddata because upstream mutations (likeuseCommentandcreate-reply) lacked sufficient pre-validation. The SDK's internal validation was the first point of failure, leading to an unhandled error.Changes Implemented:
useCommentPre-validation: Added a comprehensive pre-flight validation block withinpackages/sdk/src/modules/posts/mutations/use-comment.ts. This block now explicitly checks for the presence ofauthor,permlink,parentPermlink, andbodyin theCommentPayloadbefore callingbuildCommentOp. If any are missing, a descriptive error is thrown, providing clearer feedback to all consumers of this SDK hook.create-replyMutation Guards: Enhancedapps/web/src/api/mutations/create-reply.tswith early guards in themutationFn:text(comment body) is empty or consists only of whitespace.entry.permlink(representing the parent permlink) is present, preventing issues with unresolved parent references in complex reply scenarios.Impact:
These changes ensure that attempts to submit comments or replies with missing essential data are caught earlier in the application flow. Users will now receive more immediate and actionable feedback, preventing the SDK-level error and improving the overall stability and user experience of the comment submission process.
Fixes ECENCY-NEXT-1GQ3
This PR was automatically generated by Sentry. You can adjust this setting at any time.