Skip to content

Adding dislikes to comments UI and admin#27700

Closed
weylandswart wants to merge 13 commits into
mainfrom
adding-dislikes-to-comments-ui-and-admin
Closed

Adding dislikes to comments UI and admin#27700
weylandswart wants to merge 13 commits into
mainfrom
adding-dislikes-to-comments-ui-and-admin

Conversation

@weylandswart
Copy link
Copy Markdown
Contributor

@weylandswart weylandswart commented May 6, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

This pull request implements comment dislikes across Ghost, introducing a new database table (comment_dislikes), a Bookshelf model, service/controller methods (dislike/undislike/getCommentDislikes), API endpoints and route wiring, serializer and include-list updates, lab feature gating, net-score ordering (likes minus dislikes), frontend state and action handlers with optimistic updates, UI components (DislikeButton, updated LikeButton/LikeCount, CommentMetrics, CommentLikesModal), test fixture and mocked API updates, and schema/exporter/integrity test updates.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

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.
Description check ❓ Inconclusive No description was provided by the author, making it impossible to assess relevance to the changeset. Add a pull request description explaining the rationale, implementation approach, and any testing performed for the dislike feature.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change—adding dislike functionality to both the comments UI and admin interfaces.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch adding-dislikes-to-comments-ui-and-admin

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

@github-actions github-actions Bot added the migration [pull request] Includes migration for review label May 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

It looks like this PR contains a migration 👀
Here's the checklist for reviewing migrations:

General requirements

  • ⚠️ Tested performance on staging database servers, as performance on local machines is not comparable to a production environment
  • Satisfies idempotency requirement (both up() and down())
  • Does not reference models
  • Filename is in the correct format (and correctly ordered)
  • Targets the next minor version
  • All code paths have appropriate log messages
  • Uses the correct utils
  • Contains a minimal changeset
  • Does not mix DDL/DML operations
  • Tested in MySQL and SQLite

Schema changes

  • Both schema change and related migration have been implemented
  • For index changes: has been performance tested for large tables
  • For new tables/columns: fields use the appropriate predefined field lengths
  • For new tables/columns: field names follow the appropriate conventions
  • Does not drop a non-alpha table outside of a major version

Data changes

  • Mass updates/inserts are batched appropriately
  • Does not loop over large tables/datasets
  • Defends against missing or invalid data
  • For settings updates: follows the appropriate guidelines

@weylandswart weylandswart force-pushed the adding-dislikes-to-comments-ui-and-admin branch from b2a4556 to 9d94bdf Compare May 19, 2026 11:06
@weylandswart weylandswart marked this pull request as ready for review May 19, 2026 11:58
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/comments-ui/test/utils/mocked-api.ts (1)

139-150: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fix net-score tie-break direction to match created_at desc.

The branch for count__net_score desc, created_at desc currently returns oldest-first on ties.

Suggested fix
 if (setOrder === 'count__net_score desc, created_at desc') {
-    // Sort by net score (likes - dislikes, desc) first, then by created_at (asc)
+    // Sort by net score (likes - dislikes, desc) first, then by created_at (desc)
     this.comments.sort((a, b) => {
         const likesDiff = (b.count.likes - b.count.dislikes) - (a.count.likes - a.count.dislikes);
         if (likesDiff !== 0) {
             return likesDiff;
         }
 
         const aDate = new Date(a.created_at).getTime();
         const bDate = new Date(b.created_at).getTime();
-        return aDate - bDate; // For the rest, sort by date asc
+        return bDate - aDate; // For the rest, sort by date desc
     });
 }
🤖 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 `@apps/comments-ui/test/utils/mocked-api.ts` around lines 139 - 150, The
tie-breaker for the branch handling "count__net_score desc, created_at desc"
currently sorts by created_at ascending; in the sort callback inside the branch
where setOrder === 'count__net_score desc, created_at desc' (the
this.comments.sort(...) block), invert the date comparison so that when
net-score ties occur the more recent comment comes first (use bDate - aDate
instead of aDate - bDate) to implement created_at desc.
🤖 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/comments-ui/src/actions.ts`:
- Around line 273-286: The optimistic rollback for dislike doesn't restore a
previously liked state; update updateCommentDislikeState to use the passed-in
comment.wasLiked flag when toggling disliked to properly restore liked and
adjust likes count. Specifically, in the block that finds the reply by id, set
liked to comment.disliked ? false : (comment.wasLiked ?? r.liked), and when
computing count.likes do: if (comment.disliked) decrement dislikes and if
(!comment.disliked && comment.wasLiked) increment likes; mirror the same logic
in the other similar handlers noted (the blocks around lines 296-303 and
337-345) so rollback restores liked=true and increments likes when wasLiked was
true.
- Around line 231-244: In updateCommentLikeState, the optimistic like update
clears a prior dislike but the rollback only restores liked and likes count;
change the logic so you capture and restore the original r.disliked and
r.count.dislikes when rolling back. Concretely: when building the optimistic
reply object in updateCommentLikeState (and the analogous blocks at the other
occurrences mentioned), compute new disliked and dislikes using comment.liked
and comment.wasDisliked but also keep the prior values (r.disliked and
r.count.dislikes) available and use them to restore both disliked and dislikes
in the rollback branch so the UI fully returns to the previous state.

In `@apps/comments-ui/src/components/content/buttons/like-button.tsx`:
- Around line 119-133: The dislike button is icon-only and lacks an accessible
name; update the button rendered in the like-button component to provide an
accessible label (e.g., add aria-label="Dislike" or aria-labelledby pointing to
a visually-hidden label) so screen readers can identify it; modify the JSX where
the <button ... onClick={toggleDislike}> and the <ThumbsDownIcon ... /> are
defined to include the aria attribute (or add a hidden <span> with an id and use
aria-labelledby) and ensure tests/data-testid remain unchanged.

In `@apps/comments-ui/src/components/content/forms/sorting-form.tsx`:
- Around line 9-15: selectedOption is only set once via useState(order) so it
can get out of sync when order or the computed bestOrder (depends on
labs?.commentDislikes) changes; add a useEffect that watches order and bestOrder
and calls setSelectedOption(order) (or setSelectedOption(bestOrder) if you
compute order from labs earlier) to keep the dropdown label in sync; locate the
state variables selectedOption/setSelectedOption, the order prop/context, and
the bestOrder constant in sorting-form.tsx and update them with this useEffect
so changes to order or labs immediately reflect in the dropdown.

In `@apps/posts/src/views/comments/components/comment-metrics.tsx`:
- Around line 124-135: The likes/dislikes icon-only buttons in
comment-metrics.tsx lack accessible names; update the two icon buttons (the one
using LucideIcon.ThumbsUp and the corresponding dislikes button) to include an
explicit accessible label (e.g., aria-label or aria-labelledby) such as "Show
likes" / "Show dislikes" or "Open likes modal" / "Open dislikes modal" so screen
readers announce their purpose; ensure the aria attribute is added to the same
button elements that call setLikesModalDefaultTab/setLikesModalOpen (and the
analogous handlers for dislikes) without changing the click behavior.

In
`@ghost/core/core/server/data/migrations/versions/6.40/2026-04-22-00-00-add-comment-dislikes-table.js`:
- Around line 3-9: Add a DB-level unique constraint/index to enforce one dislike
per member per comment: modify the migration that creates the comment_dislikes
table so the pair (comment_id, member_id) is uniquely constrained (e.g., add a
composite unique index on comment_dislikes for comment_id and member_id), keep
the existing fields (id, comment_id, member_id, created_at, updated_at), and add
the corresponding index removal in the down/rollback path; reference the table
name "comment_dislikes" and the columns "comment_id" and "member_id" when
implementing the change.

In `@ghost/core/core/server/services/comments/comments-service.js`:
- Around line 142-154: Wrap the mutual-exclusivity read/delete/add sequence in a
single DB transaction so concurrent like/dislike requests cannot interleave:
start a transaction, pass the transaction object via options to
CommentDislike.findOne, CommentDislike.destroy and the subsequent create (e.g.,
the create on CommentLike/CommentDislike used in this flow), perform the
find/delete inside that transaction (optionally using a row lock / FOR UPDATE if
supported), then create the new reaction and commit; apply the same
transactional change to the other exclusivity block around lines 211-223 so both
flows run atomically.

---

Outside diff comments:
In `@apps/comments-ui/test/utils/mocked-api.ts`:
- Around line 139-150: The tie-breaker for the branch handling "count__net_score
desc, created_at desc" currently sorts by created_at ascending; in the sort
callback inside the branch where setOrder === 'count__net_score desc, created_at
desc' (the this.comments.sort(...) block), invert the date comparison so that
when net-score ties occur the more recent comment comes first (use bDate - aDate
instead of aDate - bDate) to implement created_at desc.
🪄 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: CHILL

Plan: Pro

Run ID: 7ef76a29-7e11-4b75-abf1-4dda89de37bb

📥 Commits

Reviewing files that changed from the base of the PR and between 21d76cf and 7599537.

⛔ Files ignored due to path filters (4)
  • apps/comments-ui/src/images/icons/thumbs-down.svg is excluded by !**/*.svg
  • apps/comments-ui/src/images/icons/thumbs-up.svg is excluded by !**/*.svg
  • ghost/core/test/e2e-api/admin/__snapshots__/comments.test.js.snap is excluded by !**/*.snap
  • ghost/core/test/e2e-api/admin/__snapshots__/config.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (36)
  • apps/admin-x-framework/src/api/comments.ts
  • apps/admin-x-settings/src/components/settings/advanced/labs/private-features.tsx
  • apps/comments-ui/package.json
  • apps/comments-ui/src/actions.ts
  • apps/comments-ui/src/app-context.ts
  • apps/comments-ui/src/app.tsx
  • apps/comments-ui/src/components/content/buttons/like-button.tsx
  • apps/comments-ui/src/components/content/buttons/like-count.tsx
  • apps/comments-ui/src/components/content/comment.tsx
  • apps/comments-ui/src/components/content/forms/sorting-form.tsx
  • apps/comments-ui/src/utils/api.ts
  • apps/comments-ui/test/utils/fixtures.ts
  • apps/comments-ui/test/utils/mocked-api.ts
  • apps/posts/src/views/comments/comments.tsx
  • apps/posts/src/views/comments/components/comment-likes-modal.tsx
  • apps/posts/src/views/comments/components/comment-metrics.tsx
  • apps/posts/src/views/comments/components/comment-thread-list.tsx
  • apps/posts/src/views/comments/components/comment-thread-sidebar.tsx
  • apps/posts/src/views/comments/components/comments-list.tsx
  • ghost/core/core/server/api/endpoints/comment-dislikes.js
  • ghost/core/core/server/api/endpoints/comment-replies.js
  • ghost/core/core/server/api/endpoints/comments-members.js
  • ghost/core/core/server/api/endpoints/index.js
  • ghost/core/core/server/api/endpoints/utils/serializers/output/mappers/comments.js
  • ghost/core/core/server/data/migrations/versions/6.40/2026-04-22-00-00-add-comment-dislikes-table.js
  • ghost/core/core/server/data/schema/schema.js
  • ghost/core/core/server/models/comment-dislike.js
  • ghost/core/core/server/models/comment.js
  • ghost/core/core/server/models/index.js
  • ghost/core/core/server/services/comments/comments-controller.js
  • ghost/core/core/server/services/comments/comments-service.js
  • ghost/core/core/server/web/api/endpoints/admin/routes.js
  • ghost/core/core/server/web/comments/routes.js
  • ghost/core/core/shared/labs.js
  • ghost/core/test/integration/exporter/exporter.test.js
  • ghost/core/test/unit/server/data/schema/integrity.test.js

Comment thread apps/comments-ui/src/actions.ts Outdated
Comment thread apps/comments-ui/src/actions.ts Outdated
Comment thread apps/comments-ui/src/components/content/buttons/like-button.tsx
Comment on lines +9 to 15
const [selectedOption, setSelectedOption] = useState(order);
const dropdownRef = useRef<HTMLDivElement>(null);
const bestOrder = labs?.commentDislikes ? 'count__net_score desc, created_at desc' : 'count__likes desc, created_at desc';

const options = [
{value: 'count__likes desc, created_at desc', label: t('Best')},
{value: bestOrder, label: t('Best')},
{value: 'created_at desc', label: t('Newest')},
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

Keep selectedOption synchronized with context order.

selectedOption is only initialized once. When order changes later (e.g., after labs-driven default order is applied), the dropdown label can desync.

Suggested fix
     const [selectedOption, setSelectedOption] = useState(order);
@@
     const options = [
         {value: bestOrder, label: t('Best')},
         {value: 'created_at desc', label: t('Newest')},
         {value: 'created_at asc', label: t('Oldest')}
     ];
+
+    useEffect(() => {
+        setSelectedOption(order);
+    }, [order]);

Also applies to: 25-25

🤖 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 `@apps/comments-ui/src/components/content/forms/sorting-form.tsx` around lines
9 - 15, selectedOption is only set once via useState(order) so it can get out of
sync when order or the computed bestOrder (depends on labs?.commentDislikes)
changes; add a useEffect that watches order and bestOrder and calls
setSelectedOption(order) (or setSelectedOption(bestOrder) if you compute order
from labs earlier) to keep the dropdown label in sync; locate the state
variables selectedOption/setSelectedOption, the order prop/context, and the
bestOrder constant in sorting-form.tsx and update them with this useEffect so
changes to order or labs immediately reflect in the dropdown.

Comment thread apps/posts/src/views/comments/components/comment-metrics.tsx
Comment on lines +3 to +9
module.exports = addTable('comment_dislikes', {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
comment_id: {type: 'string', maxlength: 24, nullable: false, unique: false, references: 'comments.id', cascadeDelete: true},
member_id: {type: 'string', maxlength: 24, nullable: false, unique: false, references: 'members.id', cascadeDelete: true},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: false}
});
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 | 🟠 Major | ⚡ Quick win

Enforce one dislike per member/comment at the database layer.

The current definition allows duplicate dislikes for the same (comment_id, member_id) under concurrent requests, which can inflate counts and break reaction semantics.

💡 Suggested fix
 module.exports = addTable('comment_dislikes', {
     id: {type: 'string', maxlength: 24, nullable: false, primary: true},
     comment_id: {type: 'string', maxlength: 24, nullable: false, unique: false, references: 'comments.id', cascadeDelete: true},
     member_id: {type: 'string', maxlength: 24, nullable: false, unique: false, references: 'members.id', cascadeDelete: true},
     created_at: {type: 'dateTime', nullable: false},
-    updated_at: {type: 'dateTime', nullable: false}
+    updated_at: {type: 'dateTime', nullable: false},
+    '@@UNIQUE_CONSTRAINTS@@': [
+        ['comment_id', 'member_id']
+    ]
 });
📝 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
module.exports = addTable('comment_dislikes', {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
comment_id: {type: 'string', maxlength: 24, nullable: false, unique: false, references: 'comments.id', cascadeDelete: true},
member_id: {type: 'string', maxlength: 24, nullable: false, unique: false, references: 'members.id', cascadeDelete: true},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: false}
});
module.exports = addTable('comment_dislikes', {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
comment_id: {type: 'string', maxlength: 24, nullable: false, unique: false, references: 'comments.id', cascadeDelete: true},
member_id: {type: 'string', maxlength: 24, nullable: false, unique: false, references: 'members.id', cascadeDelete: true},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: false},
'@@UNIQUE_CONSTRAINTS@@': [
['comment_id', 'member_id']
]
});
🤖 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
`@ghost/core/core/server/data/migrations/versions/6.40/2026-04-22-00-00-add-comment-dislikes-table.js`
around lines 3 - 9, Add a DB-level unique constraint/index to enforce one
dislike per member per comment: modify the migration that creates the
comment_dislikes table so the pair (comment_id, member_id) is uniquely
constrained (e.g., add a composite unique index on comment_dislikes for
comment_id and member_id), keep the existing fields (id, comment_id, member_id,
created_at, updated_at), and add the corresponding index removal in the
down/rollback path; reference the table name "comment_dislikes" and the columns
"comment_id" and "member_id" when implementing the change.

Comment on lines +142 to +154
// Remove any existing dislike (mutual exclusivity). This must always
// run so disabling and re-enabling the feature flag cannot leave a
// member with both reactions.
const existingDislike = await this.models.CommentDislike.findOne(data, options);
if (existingDislike) {
await this.models.CommentDislike.destroy({
...options,
destroyBy: {
member_id: memberModel.id,
comment_id: commentId
}
});
}
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 | 🟠 Major | 🏗️ Heavy lift

Make reaction exclusivity atomic.

These read/delete/add steps can interleave across concurrent like/dislike requests, leaving both reactions stored for one member/comment. Wrap the exclusivity flow in a single transaction and perform checks/mutations inside that transaction.

Also applies to: 211-223

🤖 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 `@ghost/core/core/server/services/comments/comments-service.js` around lines
142 - 154, Wrap the mutual-exclusivity read/delete/add sequence in a single DB
transaction so concurrent like/dislike requests cannot interleave: start a
transaction, pass the transaction object via options to CommentDislike.findOne,
CommentDislike.destroy and the subsequent create (e.g., the create on
CommentLike/CommentDislike used in this flow), perform the find/delete inside
that transaction (optionally using a row lock / FOR UPDATE if supported), then
create the new reaction and commit; apply the same transactional change to the
other exclusivity block around lines 211-223 so both flows run atomically.

@weylandswart weylandswart force-pushed the adding-dislikes-to-comments-ui-and-admin branch from 7599537 to 956c51e Compare May 19, 2026 14:59
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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/comments-ui/test/utils/fixtures.ts`:
- Around line 61-64: The reply fixture builder buildReply currently allows
override.count to replace the entire count object, causing count.dislikes to be
lost when tests pass partial counts; update buildReply to merge the default
count with override.count (same approach used in buildComment) so defaults.likes
and defaults.dislikes are preserved (e.g., compute mergedCount =
{...defaultCount, ...override.count} and use that merged object when
constructing the reply), and apply the same merge logic for the other affected
spot noted around line 71.
🪄 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: CHILL

Plan: Pro

Run ID: 9a75975b-7f3c-4c38-852d-51611bb3ca13

📥 Commits

Reviewing files that changed from the base of the PR and between 7599537 and 956c51e.

⛔ Files ignored due to path filters (5)
  • apps/comments-ui/src/images/icons/thumbs-down.svg is excluded by !**/*.svg
  • apps/comments-ui/src/images/icons/thumbs-up.svg is excluded by !**/*.svg
  • ghost/core/test/e2e-api/admin/__snapshots__/comments.test.js.snap is excluded by !**/*.snap
  • ghost/core/test/e2e-api/admin/__snapshots__/config.test.js.snap is excluded by !**/*.snap
  • ghost/core/test/e2e-api/members-comments/__snapshots__/comments.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (35)
  • apps/admin-x-framework/src/api/comments.ts
  • apps/admin-x-settings/src/components/settings/advanced/labs/private-features.tsx
  • apps/comments-ui/src/actions.ts
  • apps/comments-ui/src/app-context.ts
  • apps/comments-ui/src/app.tsx
  • apps/comments-ui/src/components/content/buttons/like-button.tsx
  • apps/comments-ui/src/components/content/buttons/like-count.tsx
  • apps/comments-ui/src/components/content/comment.tsx
  • apps/comments-ui/src/components/content/forms/sorting-form.tsx
  • apps/comments-ui/src/utils/api.ts
  • apps/comments-ui/test/utils/fixtures.ts
  • apps/comments-ui/test/utils/mocked-api.ts
  • apps/posts/src/views/comments/comments.tsx
  • apps/posts/src/views/comments/components/comment-likes-modal.tsx
  • apps/posts/src/views/comments/components/comment-metrics.tsx
  • apps/posts/src/views/comments/components/comment-thread-list.tsx
  • apps/posts/src/views/comments/components/comment-thread-sidebar.tsx
  • apps/posts/src/views/comments/components/comments-list.tsx
  • ghost/core/core/server/api/endpoints/comment-dislikes.js
  • ghost/core/core/server/api/endpoints/comment-replies.js
  • ghost/core/core/server/api/endpoints/comments-members.js
  • ghost/core/core/server/api/endpoints/index.js
  • ghost/core/core/server/api/endpoints/utils/serializers/output/mappers/comments.js
  • ghost/core/core/server/data/migrations/versions/6.40/2026-04-22-00-00-add-comment-dislikes-table.js
  • ghost/core/core/server/data/schema/schema.js
  • ghost/core/core/server/models/comment-dislike.js
  • ghost/core/core/server/models/comment.js
  • ghost/core/core/server/models/index.js
  • ghost/core/core/server/services/comments/comments-controller.js
  • ghost/core/core/server/services/comments/comments-service.js
  • ghost/core/core/server/web/api/endpoints/admin/routes.js
  • ghost/core/core/server/web/comments/routes.js
  • ghost/core/core/shared/labs.js
  • ghost/core/test/integration/exporter/exporter.test.js
  • ghost/core/test/unit/server/data/schema/integrity.test.js
✅ Files skipped from review due to trivial changes (1)
  • apps/admin-x-settings/src/components/settings/advanced/labs/private-features.tsx
🚧 Files skipped from review as they are similar to previous changes (28)
  • ghost/core/core/shared/labs.js
  • apps/comments-ui/src/app-context.ts
  • apps/comments-ui/src/components/content/comment.tsx
  • ghost/core/test/integration/exporter/exporter.test.js
  • ghost/core/core/server/data/migrations/versions/6.40/2026-04-22-00-00-add-comment-dislikes-table.js
  • ghost/core/core/server/api/endpoints/index.js
  • ghost/core/core/server/models/comment-dislike.js
  • ghost/core/core/server/services/comments/comments-controller.js
  • ghost/core/core/server/web/comments/routes.js
  • ghost/core/core/server/data/schema/schema.js
  • apps/posts/src/views/comments/components/comment-thread-list.tsx
  • apps/posts/src/views/comments/components/comments-list.tsx
  • apps/comments-ui/src/utils/api.ts
  • apps/posts/src/views/comments/components/comment-thread-sidebar.tsx
  • ghost/core/core/server/api/endpoints/comment-replies.js
  • apps/posts/src/views/comments/comments.tsx
  • ghost/core/core/server/web/api/endpoints/admin/routes.js
  • apps/posts/src/views/comments/components/comment-metrics.tsx
  • apps/comments-ui/src/components/content/forms/sorting-form.tsx
  • apps/comments-ui/test/utils/mocked-api.ts
  • ghost/core/core/server/api/endpoints/utils/serializers/output/mappers/comments.js
  • apps/admin-x-framework/src/api/comments.ts
  • ghost/core/core/server/api/endpoints/comment-dislikes.js
  • apps/comments-ui/src/components/content/buttons/like-button.tsx
  • apps/posts/src/views/comments/components/comment-likes-modal.tsx
  • apps/comments-ui/src/app.tsx
  • apps/comments-ui/src/components/content/buttons/like-count.tsx
  • ghost/core/core/server/services/comments/comments-service.js

Comment on lines 61 to 64
count: {
likes: 0
likes: 0,
dislikes: 0
},
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

Preserve default count.dislikes when overriding reply fixtures.

buildReply({...override}) currently lets override.count replace the whole count object, so dislikes can disappear when tests pass partial counts (e.g. {count: {likes: 1}}). Merge override.count into defaults like buildComment does.

Proposed fix
 export function buildReply(override: any = {}) {
     return {
         id: ObjectId().toString(),
         html: '<p>Empty</p>',
         count: {
             likes: 0,
-            dislikes: 0
+            dislikes: 0,
+            ...override.count
         },
         liked: false,
         disliked: false,
         created_at: '2022-08-11T09:26:34.000Z',
         edited_at: null,
         member: buildMember(),
         status: 'published',
-        ...override
+        ...override
     };
 }

Also applies to: 71-71

🤖 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 `@apps/comments-ui/test/utils/fixtures.ts` around lines 61 - 64, The reply
fixture builder buildReply currently allows override.count to replace the entire
count object, causing count.dislikes to be lost when tests pass partial counts;
update buildReply to merge the default count with override.count (same approach
used in buildComment) so defaults.likes and defaults.dislikes are preserved
(e.g., compute mergedCount = {...defaultCount, ...override.count} and use that
merged object when constructing the reply), and apply the same merge logic for
the other affected spot noted around line 71.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

❌ Patch coverage is 53.12500% with 180 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.75%. Comparing base (7a6d35f) to head (33733a3).
⚠️ Report is 24 commits behind head on main.

Files with missing lines Patch % Lines
.../core/server/services/comments/comments-service.js 26.89% 106 Missing ⚠️
...re/server/services/comments/comments-controller.js 24.24% 50 Missing ⚠️
ghost/core/core/server/models/comment-dislike.js 73.52% 9 Missing ⚠️
.../api/endpoints/utils/serializers/input/comments.js 0.00% 7 Missing ⚠️
...core/core/server/api/endpoints/comments-members.js 87.50% 4 Missing ⚠️
...core/core/server/api/endpoints/comment-dislikes.js 94.11% 2 Missing ⚠️
...oints/utils/serializers/output/mappers/comments.js 90.90% 1 Missing ⚠️
ghost/core/core/server/models/comment.js 97.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #27700      +/-   ##
==========================================
- Coverage   73.79%   73.75%   -0.05%     
==========================================
  Files        1522     1525       +3     
  Lines      128738   129308     +570     
  Branches    15450    15498      +48     
==========================================
+ Hits        95002    95368     +366     
- Misses      32778    33005     +227     
+ Partials      958      935      -23     
Flag Coverage Δ
admin-tests 53.54% <ø> (ø)
e2e-tests 73.75% <53.12%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@jonatansberg jonatansberg left a comment

Choose a reason for hiding this comment

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

Overall, I think this looks pretty good. One architectural question that I think we should dig into before proceeding.

The rabbit comment about UI accessibility should also be addressed.

Comment on lines +3 to +9
module.exports = addTable('comment_dislikes', {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
comment_id: {type: 'string', maxlength: 24, nullable: false, unique: false, references: 'comments.id', cascadeDelete: true},
member_id: {type: 'string', maxlength: 24, nullable: false, unique: false, references: 'members.id', cascadeDelete: true},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: false}
});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Have we considered modeling this as another field on the like rather than a separate table? Right now, the way we delete existing (dis)likes if you click both buttons is racy, meaning you can end up both liking and disliking a given comment. While there are other ways to solve for that, just keeping it as one row in the same table makes it way easier.

It would also mean we can do a single aggregation to get the net score, which should be a slight performance benefit.

Let's chat about it in the mob.

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

Labels

migration [pull request] Includes migration for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants