Repository navigation
fix: skip edge cache invalidate on draft-only content saves - #2279
Conversation
Pure draft staging on revision collections leaves live public HTML unchanged; thrashing edge tags can reseed stale Workers Cache entries.
🦋 Changeset detectedLatest commit: cf9d923 The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 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 |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-playground | cf9d923 | Jul 31 2026, 05:08 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-do | cf9d923 | Jul 31 2026, 05:10 PM |
@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-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@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: |
There was a problem hiding this comment.
This is the right fix for a real, well-described bug: draft-only saves on revision-supporting collections were unnecessarily purging public edge cache. The approach — adding a server-only liveContentChanged flag inside HandlerResponse and gating cache.invalidate on it in the PUT route — fits the existing architecture and keeps the public API envelope unchanged (unwrapResult only serializes result.data).
I read the diff, the full runtime handleContentUpdate, the PUT route, unwrapResult, the test files, and a sample of sibling route/tests. The logic for liveContentChanged is sound: revision collections report false when only data/slug are staged to drafts, true for any live-metadata mutation, and non-revision collections report true whenever live columns are touched. The tests cover the main cases and the route-level default (!== false) is safely conservative for mocks and older callers.
Headline: the implementation is correct, but one added comment violates AGENTS.md’s comment-discipline convention and should be reworded or removed.
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-cache | cf9d923 | Jul 31 2026, 05:09 PM |
Overlapping PRsThis PR modifies files that are also changed by other open PRs:
This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
There was a problem hiding this comment.
This is the right fix for the right problem: draft-only saves on revision-supporting collections were unnecessarily purging public edge cache. The approach — returning a server-only liveContentChanged flag from handleContentUpdate and gating cache.invalidate on it in the PUT route — is sound and fits the existing route/handler split.
Re-reading the runtime method, route gate, unwrapResult, MCP unwrap, the new tests, and the OpenAPI schema confirmed the logic is correct. liveContentChanged is false only when a revision collection stages pure data/slug changes into draft revisions; any live-metadata mutation (status, author, bylines, SEO, taxonomies, publishedAt) or any update to a non-revision collection returns true. The route default (!== false) remains conservative for mocks and older callers, and both unwrapResult and MCP unwrap serialize only result.data, so the flag is not leaked to clients.
This is a re-review of a previously COMMENTED review. The implementation remains correct, but the one AGENTS.md comment-discipline finding from the prior review is still present in the diff and should be addressed before merge.
Co-authored-by: emdashbot[bot] <273199577+emdashbot[bot]@users.noreply.github.com>
There was a problem hiding this comment.
This is the right fix for the right problem. Draft-only saves on revision-supporting collections were unnecessarily purging public edge cache; gating cache.invalidate on a server-only liveContentChanged flag returned by handleContentUpdate is a clean, minimal approach that fits the existing runtime/route split.
I re-read the diff, the runtime method, the PUT route, HandlerResponse, unwrapResult, and the new tests. The logic is correct:
liveContentChangedisfalseonly when a revision-supporting collection stages puredata/slugchanges into draft revisions.- Any live-metadata mutation (
status,authorId,bylines,seo,taxonomies,publishedAt) or any update to a non-revision collection returnstrue. - The route gate (
result.liveContentChanged !== false) keeps the safe default for missing flags (older callers / mocks). unwrapResultserializes onlyresult.data, so the flag never leaks to API clients.- Other mutation paths (POST create, publish, unpublish, delete, restore, permanent delete, schedule, discard-draft) remain unconditional invalidators as intended.
- Both the integration tests for the flag computation and the unit tests for the route gate are observable, non-tautological, and cover the relevant cases.
- The changeset is appropriately user-focused.
The previous AGENTS.md comment-discipline finding has been addressed: the "This ordering is intentional" wording is gone from the hydrate comment. The remaining comments are factual "why" context.
No blocking issues. LGTM.
3b53770 to
cf9d923
Compare
There was a problem hiding this comment.
This is the right fix for the right problem, and the recently-added scope is coherent with it.
Draft-only saves on revision-supporting collections were unnecessarily purging both Astro edge cache and the L2 object cache, because the PUT route and ContentRepository.update had unconditional invalidations. The PR gates Astro edge invalidation on a server-only liveContentChanged flag returned by handleContentUpdate, and avoids L2 invalidation in ContentRepository.update when the update has no live-column writes. The setDraftRevision/discardDraft paths, which also don’t touch live content, no longer bump the collection object-cache epoch either. This matches the changeset’s framing: public caches are invalidated only when live content changes.
The second newly-added concern—stripping liveRevisionId/draftRevisionId from anonymous query results—is also correct: those IDs are internal revision metadata that public pages and API consumers should not see. The stripping happens in both the read-through (getEmDashCollectionUncached) and the L2 cache-revival path, and it is correctly bypassed in edit mode and for the specific previewed entry. Cached snapshots written by earlier releases that still contain the IDs are sanitized on read.
I concentrated on the additions since the prior approval: the object-cache invalidation changes in ContentRepository, the revision-metadata stripping in query.ts, and the new unit tests in object-cache-content.test.ts. I also re-verified the previously-approved liveContentChanged logic in the runtime and PUT route, and the prior comment-discipline finding is resolved (the “This ordering is intentional” wording is gone).
Notable details that check out:
liveContentChangedisfalseonly when a revision-supported collection receives puredata/slug/locale/skipRevisionchanges; any live-metadata mutation or non-revision data update returnstrue.- The route gate
result.liveContentChanged !== falsepreserves the safe default for handlers that don’t set the flag. unwrapResultserializes onlyresult.data, soliveContentChangednever reaches API clients.- Other mutation paths (publish, unpublish, delete, restore, permanent delete, schedule, discard-draft, POST create) still invalidate the Astro edge cache as intended.
- The new tests are observable and non-tautological: they assert cache invalidation calls (or absence), response shape, and visible metadata, not implementation details asserted back at themselves.
No blocking issues. LGTM.
khoinguyenpham04
left a comment
There was a problem hiding this comment.
LGTM. Thanks @scottbuscemi
What does this PR do?
Stops pure draft content saves from calling Astro edge
cache.invalidate, which thrash-purges good public HTML and can reseed stale live content into Workers Cache.On collections with
revisionssupport (e.g. blogposts), PUT stagesdata/sluginto draft revisions only — live columns stay unchanged until publish. The PUT route still always invalidated edge tags for[collection, id], so every autosave/manual save on a published post purged public cache even though visitors would still get the same live HTML (or worse, a re-fetch could reseed a stale DB snapshot into the edge).handleContentUpdatenow returns a server-onlyliveContentChangedflag. The PUT route invalidates only when that is notfalse(missing flag still invalidates for safe defaults / mocks).unwrapResultonly serializesdata, so the flag is not leaked to API clients.Still always invalidate (unchanged): publish, unpublish, delete, restore, permanent delete, schedule, discard-draft, POST create.
This is intentionally separate from the Hyperdrive prefer-uncached fix — no Hyperdrive changes here.
Related: htmlBlock and all PT blocks share this PUT path.
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.AI-generated code disclosure
Screenshots / test output
Try this PR
Open a fresh playground →
A full working EmDash site, deployed from this branch. Each visit gets its own session-scoped sandbox: no login needed and no shared state. Try the admin, edit content, hit the public site.
Tracks
fix/draft-save-skip-edge-invalidate. Updated automatically when the playground redeploys.