Skip to content

Fixed remaining lazyRouting URL 404s in service-layer + serializer call sites#27915

Merged
allouis merged 7 commits into
hkg-1738-getUrlForResource-fieldsfrom
hkg-1738-getUrlForResource-followups
May 18, 2026
Merged

Fixed remaining lazyRouting URL 404s in service-layer + serializer call sites#27915
allouis merged 7 commits into
hkg-1738-getUrlForResource-fieldsfrom
hkg-1738-getUrlForResource-followups

Conversation

@allouis
Copy link
Copy Markdown
Collaborator

@allouis allouis commented May 15, 2026

Summary

Stacks on #27908. After the audit triggered by that PR's review, seven additional call sites of urlService.facade.getUrlForResource(...) were identified that load posts without tags/authors relations and produce /404/ URLs under config.lazyRouting for any tag- or author-filtered route in routes.yaml.

Each commit is a single-site fix with a TDD-style test that demonstrates the bug before the fix and pins the contract afterward.

Commits (7)

# Site Impact
1 services/email-service/batch-sending-service.js Newsletters ship with /404/ post URLs and broken share links
2 services/email-service/email-controller.js Email previews and test sends have broken post URLs
3 api/endpoints/email-post.js /email/<uuid>/ landing pages render with broken canonical URL
4 services/members/members-api/repositories/event-repository.js Admin activity feed (comment / click / feedback events) shows /404/ post URL on every row
5 services/comments/comments-service.js Comment moderation listing + public widget show /404/ post URL on every row
6 api/endpoints/utils/serializers/input/pages.js pages.browse?fields=url resolves to /404/ (Admin and Content API)
7 api/endpoints/utils/serializers/input/posts.js Content API branch posts.browse?fields=url resolves to /404/ on the Content API

Pattern

Most fixes are one-line withRelated extensions: add 'tags' (or 'post.tags' / 'link.post.tags' as appropriate) to the existing relation list. The two serializer fixes (commits 6 and 7) extract a small forceUrlRelationsWhenLazy(frame) helper that mirrors what #27908 added for input/posts.js's admin branch.

All fixes are gated on the same condition class as #27908: config.lazyRouting is on AND the call site is one where the URL serializer needs the relations to evaluate router filters. Eager-mode behaviour is unchanged.

Test plan

  • pnpm test:single test/unit/server/services/email-service/batch-sending-service.test.js (55/55)
  • pnpm test:single test/unit/server/services/email-service/email-controller.test.js (14/14)
  • pnpm test:single test/unit/api/endpoints/email-post.test.js (1/1, new file)
  • pnpm test:single test/unit/server/services/members/members-api/repositories/event-repository.test.js (35/35)
  • pnpm test:single test/unit/server/services/comments/comments-service.test.js (1/1, new file)
  • pnpm test:single test/unit/api/canary/utils/serializers/input/pages.test.js (22/22)
  • pnpm test:single test/unit/api/canary/utils/serializers/input/posts.test.js (29/29 of mine; 2 pre-existing html-to-mobiledoc env failures unrelated)
  • Smoke test against a site running config.lazyRouting: true with a tag-filtered collection in routes.yaml: send a newsletter / open a comment moderation page / open the admin activity feed → all post URLs should be the real post URL, not /404/

allouis added 7 commits May 15, 2026 09:21
ref https://linear.app/tryghost/issue/HKG-1738/

batch-sending-service loads the post that gets threaded through the email
renderer to build the post URL embedded in the newsletter (via
urlService.facade.getUrlForResource). The previous load only included
posts_meta+authors; under lazyRouting the URL serializer evaluates each
router's NQL filter against the loaded record and tag-filtered routes
need 'tags' loaded too, otherwise every newsletter ships with /404/
links for sites using collection routing.
ref https://linear.app/tryghost/issue/HKG-1738/

email-controller loads the post for both preview and send-test endpoints,
which then render through the email-renderer (same getUrlForResource
path as batch-sending). Add 'tags' to the existing posts_meta+authors
load so tag-filtered routes resolve under lazyRouting.
ref https://linear.app/tryghost/issue/HKG-1738/

The /email/<uuid>/ endpoint returns a post that goes through the
email-posts output mapper → mappers.posts → url.forPost, which calls
urlService.facade.getUrlForResource. Without tags+authors loaded the
URL serializer can't evaluate tag- or author-filtered routes under
lazyRouting and the rendered page embeds /404/ as the post URL.

The fix merges with caller-supplied withRelated rather than overwriting,
so ?include= options stay intact.
ref https://linear.app/tryghost/issue/HKG-1738/

getCommentEvents, getClickEvents and getFeedbackEvents all emit a post
(or link.post) per row. The activity-feed mappers call url.forPost on
that post, routing to urlService.facade.getUrlForResource. Without
tags/authors loaded under lazyRouting every row's post URL is /404/
for tag- or author-filtered routes.

Add post.tags / post.authors to the three withRelated lists (and
link.post.tags / link.post.authors for clicks where the post is one
relation deeper).
ref https://linear.app/tryghost/issue/HKG-1738/

getAdminAllComments emits a post per comment row for the admin moderation
listing. mappers/comments.js calls url.forPost on the embedded post →
urlService.facade.getUrlForResource. Without post.tags / post.authors
loaded under lazyRouting each row's post URL resolves to /404/ for
tag- or author-filtered routes.
ref https://linear.app/tryghost/issue/HKG-1738/

input/pages.js's defaultRelations had the same shape as the unfixed
input/posts.js — a thin column request like ?fields=id,url short-circuits
without loading any relations. Under lazyRouting the URL serializer
needs tags+authors to evaluate filtered routes; without them a
?fields=url request resolves every URL to /404/.

Mirrors the fix in input/posts.js: a forceUrlRelationsWhenLazy helper
called from both the admin defaultRelations path and the Content API
branch (which uses mapWithRelated rather than defaultRelations).
ref https://linear.app/tryghost/issue/HKG-1738/

The Content API branch of input/posts.js uses mapWithRelated rather than
defaultRelations, so the lazyRouting fix in the previous PR (#27908)
didn't cover Content API consumers passing ?fields=url. Same /404/
symptom: the URL serializer can't evaluate tag- or author-filtered
routes against a thin record.

Extracted the conditional into a forceUrlRelationsWhenLazy helper
called from both the admin defaultRelations path and the Content API
branch, so the two paths stay in sync.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e3ce14b2-bd98-4348-b17e-6374869c8ec8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hkg-1738-getUrlForResource-followups

Comment @coderabbitai help to get the list of available commands and usage tips.

@allouis allouis merged commit 3d8322d into hkg-1738-getUrlForResource-fields May 18, 2026
41 of 44 checks passed
@allouis allouis deleted the hkg-1738-getUrlForResource-followups branch May 18, 2026 10:07
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