Skip to content

fix: skip edge cache invalidate on draft-only content saves - #2279

Merged
khoinguyenpham04 merged 4 commits into
mainfrom
fix/draft-save-skip-edge-invalidate
Aug 3, 2026
Merged

khoinguyenpham04 merged 4 commits into
mainfrom
fix/draft-save-skip-edge-invalidate

Conversation

@scottbuscemi

@scottbuscemi scottbuscemi commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

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 revisions support (e.g. blog posts), PUT stages data/slug into 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).

handleContentUpdate now returns a server-only liveContentChanged flag. The PUT route invalidates only when that is not false (missing flag still invalidates for safe defaults / mocks). unwrapResult only serializes data, 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

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable). Do not include messages.po changes except in translation PRs — a workflow extracts catalogs on merge to main.
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion: n/a (bug fix; maintainer)

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: grok-4.5 / opencode

Screenshots / test output

pnpm --filter emdash exec vitest run \
  tests/unit/astro/content-routes-cache-invalidate.test.ts \
  tests/integration/content/draft-save-live-content-changed.test.ts

Test Files  2 passed (2)
     Tests  8 passed (8)

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.

Pure draft staging on revision collections leaves live public HTML
unchanged; thrashing edge tags can reseed stale Workers Cache entries.
@changeset-bot

changeset-bot Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cf9d923

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/plugin-mcp-smoke Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

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

@github-actions github-actions Bot added review/needs-review No maintainer or bot review yet area/core size/L labels Jul 29, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground cf9d923 Jul 31 2026, 05:08 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-do cf9d923 Jul 31 2026, 05:10 PM

@pkg-pr-new

pkg-pr-new Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@2279

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@2279

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/@emdash-cms/auth-atproto@2279

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@2279

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@2279

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/contentful-to-portable-text@2279

emdash

npm i https://pkg.pr.new/emdash@2279

create-emdash

npm i https://pkg.pr.new/create-emdash@2279

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@2279

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/@emdash-cms/plugin-cli@2279

@emdash-cms/plugin-types

npm i https://pkg.pr.new/@emdash-cms/plugin-types@2279

@emdash-cms/registry-client

npm i https://pkg.pr.new/@emdash-cms/registry-client@2279

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/@emdash-cms/registry-lexicons@2279

@emdash-cms/registry-verification

npm i https://pkg.pr.new/@emdash-cms/registry-verification@2279

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/@emdash-cms/sandbox-workerd@2279

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@2279

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@2279

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@2279

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@2279

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@2279

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@2279

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/@emdash-cms/plugin-field-kit@2279

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@2279

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@2279

commit: cf9d923

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache cf9d923 Jul 31 2026, 05:09 PM

@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-review No maintainer or bot review yet labels Jul 29, 2026
@github-actions github-actions Bot added review/needs-rereview New commits since the last review overlap and removed review/awaiting-author Reviewed; waiting on the author to respond labels Jul 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Overlapping PRs

This PR modifies files that are also changed by other open PRs:

This may cause merge conflicts or duplicated work. A maintainer will coordinate.

@khoinguyenpham04 khoinguyenpham04 added the bot:review Trigger an emdashbot code review on this PR label Jul 31, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/core/src/astro/types.ts Resolved
@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Jul 31, 2026
@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-rereview New commits since the last review labels Jul 31, 2026
Co-authored-by: emdashbot[bot] <273199577+emdashbot[bot]@users.noreply.github.com>
@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/awaiting-author Reviewed; waiting on the author to respond labels Jul 31, 2026
@khoinguyenpham04 khoinguyenpham04 added the bot:review Trigger an emdashbot code review on this PR label Jul 31, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • liveContentChanged is false only when a revision-supporting collection stages pure data/slug changes into draft revisions.
  • Any live-metadata mutation (status, authorId, bylines, seo, taxonomies, publishedAt) or any update to a non-revision collection returns true.
  • The route gate (result.liveContentChanged !== false) keeps the safe default for missing flags (older callers / mocks).
  • unwrapResult serializes only result.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.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Jul 31, 2026
@github-actions github-actions Bot added the review/approved Approved; no new commits since label Jul 31, 2026
@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/needs-rereview New commits since the last review review/approved Approved; no new commits since labels Jul 31, 2026
@khoinguyenpham04
khoinguyenpham04 force-pushed the fix/draft-save-skip-edge-invalidate branch from 3b53770 to cf9d923 Compare July 31, 2026 17:04
@github-actions github-actions Bot mentioned this pull request Aug 1, 2026
11 of 18 tasks
@khoinguyenpham04 khoinguyenpham04 added the bot:review Trigger an emdashbot code review on this PR label Aug 3, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • liveContentChanged is false only when a revision-supported collection receives pure data/slug/locale/skipRevision changes; any live-metadata mutation or non-revision data update returns true.
  • The route gate result.liveContentChanged !== false preserves the safe default for handlers that don’t set the flag.
  • unwrapResult serializes only result.data, so liveContentChanged never 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.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Aug 3, 2026
@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/needs-rereview New commits since the last review labels Aug 3, 2026

@khoinguyenpham04 khoinguyenpham04 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @scottbuscemi

@khoinguyenpham04
khoinguyenpham04 merged commit c1f6768 into main Aug 3, 2026
52 checks passed
@khoinguyenpham04
khoinguyenpham04 deleted the fix/draft-save-skip-edge-invalidate branch August 3, 2026 10:55
@emdashbot emdashbot Bot mentioned this pull request Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core review/approved Approved; no new commits since size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants