Repository navigation
Conversation
🦋 Changeset detectedLatest commit: 7244167 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
The approach is sound. Public URLs are resolved at render time, only when public templates read settings through getSiteSettings(), getSiteSetting() and <Media>. Stored URLs, the REST and admin APIs, and getSiteSettingsWithDb() stay on the internal media route. Local <Media> values are also handled directly, so no database-dependent provider is built with an empty context. Both reviewers approved and found nothing needing changes. They checked request-context propagation through the anonymous, authenticated and scoped-db paths, settings cache isolation, adapter fallbacks when publicUrl is unset, the tests, the changeset and the docs. No extra database queries are added. The review was static; tests, builds and lint were not run.
Reviewed by anthropic/claude-opus-5-5 and openai/gpt-6.1-sol.
|
I have read the CLA Document and I hereby sign the CLA |
|
Recheck |
|
This PR is waiting on its author because it has merge conflicts with |
Sites with an R2 custom domain or S3 CDN still served the logo, favicon, and default social image from getSiteSettings() through the Worker media route, because the settings reader has no Astro.locals and so never saw the storage adapter. Middleware now puts the public media URL resolver on the request context, and the public settings readers rewrite those URLs on a per-request copy. The cached snapshot, admin API, and stored values keep the internal route, because the admin persists media URLs into content and site transfer only rewrites internal paths. <Media> resolved local media through getMediaProvider(), which builds the local provider without a database and threw on every render. It now handles local media like <Image>, <Gallery>, and <Video>, which also makes it honor publicUrl.
0e91d75 to
3d35b89
Compare
There was a problem hiding this comment.
The approach is sound. Public media URLs are resolved at render time, so stored URLs, the REST and admin APIs, and getSiteSettingsWithDb() keep the internal media route. Local <Media> values are handled directly, so no database-dependent provider is built with an empty context. Both reviewers approved and found nothing needing changes. They checked request-context propagation across the anonymous, authenticated and scoped-db paths, settings cache isolation, adapter fallbacks when publicUrl is unset, the tests, the changeset and the docs. No extra database queries are added. The review was static; tests, builds and lint were not run.
Reviewed by anthropic/claude-opus-5-5 and openai/gpt-6.1-sol.
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-test
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-loader
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
upgrade-emdash
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-ai-search
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
|
Thanks for contributing to EmDash! 🎉 Join the EmDash Discord, then run |
What does this PR do?
With
publicUrlset on R2 or S3 storage, the site logo, favicon, and default social image fromgetSiteSettings()/getSiteSetting()still point at/_emdash/api/media/file/{key}, so every template that renderssettings.logo.urlproxies those bytes through the Worker. This PR appliespublicUrlto those URLs at read time.It also fixes
<Media>(emdash/ui) for media library items. It looked up thelocalprovider throughgetMediaProvider(), which creates it with an empty context, so rendering threwLocal media provider requires database connection.<Media>now handles local media the same way<Image>,<Gallery>, and<Video>do, and so picks uppublicUrlas well.I reported #508 and run EmDash on Cloudflare with R2. #675 fixed the render components; this covers the remaining read-time surfaces. It replaces the server-side half of #729, which has gone stale with conflicts. That PR's first commit merged as #675.
Why the API and admin URLs stay internal
#729 also changed the media REST API, the plugin
ctx.media.upload()result, the local provider'spreviewUrl, and the admin settings API to return CDN URLs. This PR leaves them on the internal route because those URLs get stored:item.urlinto content and settings (mediaItemToImageAttrsinPortableTextEditor.tsx, the logo/favicon pickers inGeneralSettings.tsx)./_emdash/api/media/file/paths (transfer/format/media-refs.ts), so stored CDN URLs would not be carried across a transfer.getMediaThumbnailUrl/getMediaPreviewUrl), so CDN URLs would load full-size originals in the media grid.How it works
publicMediaUrlresolver on the request context in the same place it buildslocals.emdash.getPublicMediaUrl, whichgetSiteSettings()reads because it has noAstro.locals. The redirect middleware setssiteSettingson the parent context the same way.getSiteSettings()/getSiteSetting()rewrite the three media URLs on a per-request copy throughbuildRenderMediaUrl. The cached settings snapshot, the object cache entry, andgetSiteSettingsWithDb()(admin API, sitemap, robots) keep the internal route.publicUrl, output is unchanged: the R2 and S3 adapters return the internal route.Not in scope: when
publicUrlis set,<Image>with stored dimensions still sends the absolute CDN URL through Astro's/_imageendpoint, which fails on Workers (reported in a comment on #729). That needs its own change.Related: #508 (closed automatically when #675 merged), #675, #729
Type of change
Your connection to this change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runAI assistance disclosure
Screenshots / test output
Not applicable (no UI changes).
Manual check on a local site from
templates/starter-cloudflare(astro dev, local D1 and R2), withpublicUrlpointed at a separate origin that proxies to the media route:og:image, and<Media>from thepublicUrlorigin, and the browser loads them from there.<Media>with a bare media id stays on/_emdash/api/media/file/. The media and settings APIs still return the internal route.main, the same pages render all three settings images from/_emdash/api/media/file/, and a page containing<Media>for a library item returns an empty body.New tests, each confirmed to fail with the source change reverted:
tests/unit/settings/settings.test.ts: logo, favicon, and default OG image use the storage public URL throughgetSiteSettings()andgetSiteSetting(), and the cached snapshot stays on the internal route.tests/unit/astro/middleware-prerender.test.ts: the resolver reaches page renders on the anonymous, authenticated, and scoped-db paths.tests/repro/image-render.render.test.ts:<Media>with thelocalprovider registered as in production (previously threw) renders the public URL for a storage key and the internal route for a bare id.