Skip to content

🐛 Fixed comment counts for lazy loaded posts#28545

Merged
jonatansberg merged 2 commits into
mainfrom
jonatan-onc-1832-comment-counts-missing-for-post-cards-on-archive-pages
Jun 12, 2026
Merged

🐛 Fixed comment counts for lazy loaded posts#28545
jonatansberg merged 2 commits into
mainfrom
jonatan-onc-1832-comment-counts-missing-for-post-cards-on-archive-pages

Conversation

@jonatansberg

Copy link
Copy Markdown
Member

What changed

  • Fixed the frontend comment-count loader so it fetches counts for markers inserted after initial page load.
  • Added a JSDOM regression test covering lazy-loaded post cards.

Why

Archive pagination inserts post cards after the initial page load. The mutation observer detected those new comment count markers, but it created a debounced fetch function without invoking it, so the counts for lazy loaded posts were never requested.

Testing

  • CI=true pnpm --dir ghost/core test:single test/unit/frontend/src/comment-counts.test.js
  • Pre-commit hook ran ESLint for the changed JS files.

ref https://linear.app/ghost/issue/ONC-1832/comment-counts-missing-for-post-cards-on-archive-pages

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2ece9938-4d82-4ccf-ac21-beafbe583c1f

📥 Commits

Reviewing files that changed from the base of the PR and between b04fa70 and aa585c0.

📒 Files selected for processing (2)
  • ghost/core/core/frontend/src/comment-counts/comment-counts.js
  • ghost/core/test/unit/frontend/src/comment-counts.test.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • ghost/core/core/frontend/src/comment-counts/comment-counts.js
  • ghost/core/test/unit/frontend/src/comment-counts.test.js

Walkthrough

The PR creates a single reusable debouncedFetchCounts wrapper and updates the MutationObserver to call it once per observer callback after collecting all new post IDs. A new unit test suite loads the production script, stubs fetch responses for post ids, appends a post card, and asserts the counts API was requested for the new id and the DOM renders the expected pluralized text.

Suggested reviewers

  • kevinansfield
  • 9larsons
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title references a bug fix for comment counts on lazy-loaded posts, which directly aligns with the main change: fixing the debounce logic to properly fetch counts for dynamically inserted post cards.
Description check ✅ Passed The description clearly explains what changed (fixed comment-count loader and added regression test), why it was needed (mutation observer wasn't invoking debounced function), and provides testing details.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jonatan-onc-1832-comment-counts-missing-for-post-cards-on-archive-pages

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.

@nx-cloud

nx-cloud Bot commented Jun 12, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit aa585c0

Command Status Duration Result
nx run ghost:test:ci:integration:no-coverage ✅ Succeeded 1m 59s View ↗
nx run ghost:test:ci:e2e:no-coverage ✅ Succeeded 10m 17s View ↗
nx run ghost:test:ci:integration ✅ Succeeded 1m 9s View ↗
nx run ghost:test:ci:e2e ✅ Succeeded 3m 46s View ↗
nx run ghost:test:ci:legacy ✅ Succeeded 3m 32s View ↗
nx build @tryghost/signup-form ✅ Succeeded <1s View ↗
nx build @tryghost/admin-toolbar ✅ Succeeded <1s View ↗
nx build @tryghost/comments-ui ✅ Succeeded <1s View ↗
Additional runs (10) ✅ Succeeded ... View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-12 09:48:04 UTC

ref https://linear.app/ghost/issue/ONC-1832/comment-counts-missing-for-post-cards-on-archive-pages

Archive pagination inserts post cards after the initial page load. Their comment count markers were detected, but the mutation observer created a debounced fetch without invoking it, so the new counts were never requested.
@jonatansberg jonatansberg marked this pull request as ready for review June 12, 2026 09:09

@coderabbitai coderabbitai Bot left a comment

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.

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 `@ghost/core/test/unit/frontend/src/comment-counts.test.js`:
- Around line 23-25: The test uses the Mocha-style hook before(...) which Vitest
doesn't alias; change the hook call from before(...) to beforeAll(...) where
scriptContent is initialized (the before block that reads comment-counts.js) so
the file is loaded in a Vitest-compatible way; update any matching before(...)
reference in comment-counts.test.js that initializes scriptContent to
beforeAll(...) and keep the same callback and fs.readFileSync logic unchanged.
🪄 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: 9c649096-ee3f-421f-8bcc-6aa9a804b6de

📥 Commits

Reviewing files that changed from the base of the PR and between cb39915 and b04fa70.

📒 Files selected for processing (2)
  • ghost/core/core/frontend/src/comment-counts/comment-counts.js
  • ghost/core/test/unit/frontend/src/comment-counts.test.js

Comment thread ghost/core/test/unit/frontend/src/comment-counts.test.js Outdated
ref https://linear.app/ghost/issue/ONC-1832/comment-counts-missing-for-post-cards-on-archive-pages

The regression now runs through the ghost/core Vitest unit suite instead of relying on the legacy Mocha single-test path.
@jonatansberg jonatansberg force-pushed the jonatan-onc-1832-comment-counts-missing-for-post-cards-on-archive-pages branch from b04fa70 to aa585c0 Compare June 12, 2026 09:32
@jonatansberg jonatansberg enabled auto-merge (squash) June 12, 2026 09:39
@jonatansberg jonatansberg merged commit dbedeec into main Jun 12, 2026
50 checks passed
@jonatansberg jonatansberg deleted the jonatan-onc-1832-comment-counts-missing-for-post-cards-on-archive-pages branch June 12, 2026 09:49
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.

2 participants