Skip to content

Fix comments UI nullable reply HTML handling#28938

Open
PedroMarianoAlmeida wants to merge 2 commits into
TryGhost:mainfrom
PedroMarianoAlmeida:fix-comments-ui-comment-types
Open

Fix comments UI nullable reply HTML handling#28938
PedroMarianoAlmeida wants to merge 2 commits into
TryGhost:mainfrom
PedroMarianoAlmeida:fix-comments-ui-comment-types

Conversation

@PedroMarianoAlmeida

@PedroMarianoAlmeida PedroMarianoAlmeida commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Why I am making it

This started as a comments-ui typecheck cleanup. Comment.html is typed as string | null, because deleted comment replies can be returned with html: null when they need to stay visible as tombstones for visible descendant replies.

Some reply paths still treated comment.html as always being a string when rendering or building the “reply to” snippet. This makes those paths narrow nullable HTML explicitly and adds regression coverage for the deleted reply tombstone case.

What it does

  • Narrows nullable comment HTML before rendering comment content.
  • Avoids generating a reply snippet from a reply when its HTML is null.
  • Only renders ReplyFormBox when an openForm exists.
  • Adds a comments-ui E2E regression test for a deleted reply with html: null and a visible child reply.
  • Verifies the deleted reply renders as a tombstone without comment content, reply action, or like action.

Type errors fixed

This removes the apps/comments-ui/src/components/content/comment.tsx errors caused by nullable comment HTML and optional reply form state:

  • Argument of type 'Comment' is not assignable to parameter of type '{ html?: string | undefined; }'
  • Type 'string | null' is not assignable to type 'string | undefined'
  • Type 'OpenCommentForm | undefined' is not assignable to type 'OpenCommentForm'
  • Type 'string | null' is not assignable to type 'string'

Why developers need it

This cleans up the comments-ui typecheck path and protects the threaded comments UI from crashing or exposing actions for deleted reply tombstones when API data contains html: null.

Testing

  • rtk pnpm --filter @tryghost/comments-ui test:acceptance test/e2e/content.test.ts
  • rtk pnpm --dir apps/comments-ui exec eslint --cache -- test/e2e/content.test.ts
    • Exits 0 with the existing warning that the test file is ignored because comments-ui lint config only targets src.

Checklist

  • I've read and followed the Contributor Guide
  • I've explained my change
  • I've written an automated test to prove my change works

Guard nullable comment HTML before rendering bodies or generating reply snippets, and only pass concrete open reply forms to ReplyFormBox.
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Comment rendering now treats missing HTML as absent content: opening the inline reply form is blocked when a published comment has no HTML, published bodies render only when HTML exists, and both published and unpublished layouts require an open form before showing the reply form. The e2e suite adds coverage for a deleted reply with null HTML rendering as a tombstone without action controls while a nested visible child reply remains visible.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: handling nullable reply HTML in the comments UI.
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.
Description check ✅ Passed The description matches the code changes and added regression test for nullable comment HTML and deleted reply tombstones.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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.

1 participant