Skip to content

fix(publisher): resolve custom media fields on entry routes - #662

Draft
rodrigoc-neu-Lab wants to merge 1 commit into
CoreBunch:mainfrom
rodrigoc-neu-Lab:fix/entry-route-media-fields
Draft

rodrigoc-neu-Lab wants to merge 1 commit into
CoreBunch:mainfrom
rodrigoc-neu-Lab:fix/entry-route-media-fields

Conversation

@rodrigoc-neu-Lab

Copy link
Copy Markdown

Summary

On a post-type entry route (/<routeBase>/<slug>), {currentEntry.<field>} for a custom media field rendered the raw media id. An image bound with <img src="{currentEntry.heroImage}"> published as src="y36mE-NX00zzcNWE7aSfj".

The same binding inside a data.rows loop renders /uploads/…, because the loop source resolves every schema-declared media field through resolvedMediaOverlay. The entry stack is built by publishedDataRowToLoopItem, which spread the raw cells and resolved only the built-in featuredMedia. A template author therefore saw working images in a list and broken ones on the matching detail page.

This PR:

  • adds publishedDataRowToEntryItem(db, row, fields) in server/publish/loopPrefetch.ts. It resolves the row's media cells with the same helpers the loop source uses (collectMediaIds → resolveMediaIdsToPaths → resolvedMediaOverlay), so single media, multi-media and repeater media behave the same in both places;
  • exports those three helpers from the @core/loops barrel instead of deep-importing sources/dataRowsMedia;
  • makes publishedDataRowToLoopItem private and has it take the resolved overlay, leaving one way to build an entry frame;
  • moves all three entry-stack callers to the new helper:
    • public entry routes (publicRenderer.ts), which read the table through getDataTable(MAIN_SCOPE) so the branch-scope architecture gate stays satisfied;
    • branch previews (branchPreview.ts) and draft previews (handlers/cms/data/preview.ts), which already had the table and pass its fields.

Also documents the behaviour in docs/features/content-storage.md.

mediaPrefetch already collects resolved /uploads/ scalars from the entry stack, so these images now also get their library alt text, srcset and intrinsic size, like featuredMedia does.

Found while migrating a Webflow site: its project and service detail templates bind several custom image fields, and every one of them rendered as an id.

Verification

  • bun run build
  • bun test (8 failures in toolbar.test.ts / selectorStability.test.ts also occur on a clean origin/main checkout. Those tests build paths with new URL(…).pathname, which percent-encodes a space in the checkout path. They are unrelated to this PR.)
  • bun run lint
  • Docker/deployment check, if relevant (not relevant)

Tests:

  • loopPrefetch.test.ts: new test showing that scalar and multi-value media fields resolve to public paths and that a missing asset is dropped. The existing authorship test now runs through the new helper.
  • cmsTemplateRoutes.test.ts: the fake DB answers the new table-schema read with no rows, which keeps the existing route fixtures unchanged.

Checked by hand on a local install: a template's custom image fields now publish /uploads/… URLs with srcset, matching the same entries in loops.

Checklist

  • Tests cover behavior changes.
  • Docs were updated when behavior, config, deployment, or public surfaces changed.
  • No compatibility shim was added for old pre-release behavior.
  • No secrets, local databases, uploads, or generated artifacts are included.

🤖 Generated with Claude Code

On a post-type entry route, `{currentEntry.<field>}` for a custom media
field rendered the raw media id, while the same binding inside a
data.rows loop rendered the /uploads/ path: the entry frame spread raw
cells and only resolved the built-in featuredMedia.

publishedDataRowToEntryItem now resolves the row's media cells with the
same helpers the loop source uses, and every entry-stack caller (public
entry route, branch preview, draft preview) goes through it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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