🐛 Fixed "linked comment is no longer available" error after unhiding a comment#28493
Conversation
…a comment no ref - comment permalinks (the "View on post" action in admin and shared comment links) load the comment via GET /api/members/comments/:id/ to decide whether to scroll to it or show an error notice - on hosts that cache the members API at the edge (purged via the X-Cache-Invalidate header), comment mutations only purged the post browse and parent replies paths, so the single-comment read path kept serving a stale "hidden" payload after a comment was unhidden, and kept serving hidden content after a comment was hidden - comment mutations now also purge /api/members/comments/:id/, and the six duplicated copies of the purge-path logic are consolidated into the existing shared setCacheInvalidationHeaders helper Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (4)
WalkthroughThis PR refactors cache-invalidation header construction in the comments controller from duplicated per-method logic to a centralized Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ast-grep (0.43.0)ghost/core/test/e2e-api/admin/comments.test.jsghost/core/test/e2e-api/members-comments/comments.test.jsThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
Unhiding a comment in admin and then using "View on post" can land on the post with the comments section showing "The linked comment is no longer available." instead of scrolling to the comment.
The permalink flow in comments-ui (
fetchScrollTarget) loads the target viaGET /api/members/comments/:id/and requiresstatus === 'published'. On hosts that cache the members API at the edge (purged via theX-Cache-Invalidateheader), every comment mutation purged only:/api/members/comments/post/<postId>//api/members/comments/<parentId>/replies/…but never the single-comment read path. So after unhiding,
/api/members/comments/:id/kept serving the stale "hidden" payload (while the freshly-purged browse path rendered the comment right below the error). The reverse direction is worse: after hiding a comment, the cached read endpoint kept serving its content until TTL.These purge paths predate the permalink feature (added Dec 2025 in 3df0e8c), which introduced the dependency on the read endpoint — closest precedent is a489d5a, which added the
/replies/path for the same reason.Solution
setCacheInvalidationHeadersnow also emits/api/members/comments/<id>/(appended last, so existing unanchored matchers stay valid)stringMatchingso snapshots stay stable across runsNote for review: this only requests the purge — worth confirming with the Pro team that the edge purge rules cover
/api/members/comments/:id/(they should if matching is prefix-based on/api/members/comments/).Local verification:
test/unit/server/services/comments(39 passing),test/e2e-api/members-comments(102 passing, twice — no snapshot drift),test/e2e-api/admin/comments.test.js(88 passing),test/e2e-api/admin/member-commenting.test.js(30 passing).Replaces #28492 (same commit, recreated from an in-repo branch instead of a fork).
🤖 Generated with Claude Code