Skip to content

Keep the edit proxy on collection reads in edit mode - #2970

Merged
ascorbic merged 1 commit into
emdash-cms:mainfrom
jakevis:fix/collection-edit-proxy
Sep 9, 2026
Merged

ascorbic merged 1 commit into
emdash-cms:mainfrom
jakevis:fix/collection-edit-proxy

Conversation

@jakevis

@jakevis jakevis commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes visual editing on list pages. Entries returned by getEmDashCollection always carried a no-op edit proxy, in every mode, so spreading {...entry.edit.title} on a list rendered no annotation and the toolbar never picked the element up. Only pages built from getEmDashEntry were click-to-edit.

getEmDashCollection routed every read through loadCollectionCached, which reduces entries to a JSON snapshot (entrySnapshot) and rebuilds them with reviveEntry. A Proxy cannot survive that round-trip, so reviveEntry re-attaches the no-op — discarding the createEditable proxy that getEmDashCollectionUncached built one line earlier.

The round-trip ran unconditionally, not only on a cache hit, so the annotation was lost even with no L2 backend configured. shouldBypass() governs whether a snapshot is stored, not whether entries pass through it, which left this invariant — stated above entrySnapshot — unenforced on the load path:

L2 is only consulted for anonymous, non-preview, non-edit requests (see shouldBypass in object-cache), where edit is always the no-op variant — so dropping and recreating it is lossless.

This bypasses the snapshot for preview and edit-mode requests, mirroring the serveDrafts branch getEmDashEntry already uses for the same reason. The request-scoped cache still collapses duplicate queries within a render, so repeated widget reads are unaffected; only the distributed snapshot is skipped, and only for requests that must never be shared anyway.

Closes #2785

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) — not applicable, no admin UI strings
  • I have added and reviewed the user-facing changeset (if this PR changes a published package)
  • New features link to an approved Discussion — not applicable, bug fix
  • I have included screenshots below if this PR changes the UI — not applicable, no UI change

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 5 (Claude Code)

Screenshots / test output

No UI change.

tests/unit/query-collection-edit-proxy.test.ts reproduces the bug. Against main the first case fails:

 × annotates fields in edit mode, matching getEmDashEntry
   AssertionError: expected {} to have property "data-emdash-ref"
 Tests  1 failed | 1 passed (2)

With the fix, both pass. The second case pins the other half of the contract — that no annotations are emitted outside edit mode — so the bypass can't leak refs into shared HTML.

Full packages/core unit suite on this branch:

 Test Files  343 passed (343)
      Tests  4257 passed (4257)

pnpm typecheck, pnpm lint and pnpm format all clean.

How this was found

Reported independently while building a site on emdash@0.32.0: FAQ, house-rules and supporters list pages were not editable, while the event detail page was. Confirmed at runtime in a single request with editMode: true — getEmDashCollection returned Object.keys(entry.edit) === [] while getEmDashEntry returned a real annotation for the same session. Details in #2785 (comment).

@changeset-bot

changeset-bot Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cd89ed1

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/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
create-emdash Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/release-service 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

@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, implemented in a way that fits EmDash's architecture.

The bug is real: getEmDashCollection unconditionally routed reads through loadCollectionCached, whose entrySnapshot/reviveEntry round-trip drops the live edit proxy and re-attaches a no-op, so list-page fields were never annotated in visual editing mode. The fix mirrors the existing serveDrafts bypass in getEmDashEntry and avoids the snapshot for edit/preview requests, preserving the proxy. The object-cache layer already bypasses storage for these requests via shouldBypass(), so this change only enforces the same invariant on the snapshot path while keeping the per-request deduplication that requestCached provides.

I checked:

  • The diff, the full packages/core/src/query.ts, and the new test.
  • object-cache/index.ts — shouldBypass() already returns true for edit/preview, so L2 reads/writes were already skipped; the serialization step was the only remaining leak.
  • request-cache.ts and request-context.ts — the per-request cache is ALS-keyed, so branching on serveDrafts inside the loader cannot leak edit-mode results across requests.
  • editable.ts — the annotation semantics and the no-op proxy behave as the test asserts.
  • The changeset against .changeset/README.md — it names the public API (getEmDashCollection) and the user-visible symptom (list pages not click-to-edit); proportionate for a patch.

No AGENTS.md violations: no new admin UI strings, no SQL changes, no content-table locale-filter changes, no logged-out hot-path queries, no unsafe comments, and the changeset is user-facing. The test reproduces the reported failure and pins the non-edit contract as well.

@github-actions github-actions Bot added the review/approved Approved; no new commits since label Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@jakevis
jakevis force-pushed the fix/collection-edit-proxy branch from e1c7425 to 3cf9236 Compare September 9, 2026 03:48
@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/approved Approved; no new commits since labels Sep 9, 2026
Visual editing could not work on any list page. `getEmDashCollection`
routed every read through `loadCollectionCached`, which reduces entries to
a JSON snapshot via `entrySnapshot` and rebuilds them with `reviveEntry`.
A `Proxy` cannot survive that round-trip, so `reviveEntry` re-attaches the
no-op variant — discarding the `createEditable` proxy that
`getEmDashCollectionUncached` had just built. Spreading
`{...entry.edit.title}` on a list therefore rendered no annotation, and
the toolbar never picked the element up.

The round-trip ran unconditionally, not only on a cache hit, so the
annotation was lost even with no L2 backend configured. `shouldBypass()`
governs whether a snapshot is *stored*, which left the invariant stated
above `entrySnapshot` — that `edit` is always the no-op on the paths L2
serves — unenforced on the load path.

Bypass the snapshot for preview and edit-mode requests, mirroring the
`serveDrafts` branch `getEmDashEntry` already uses for the same reason.
The request-scoped cache still collapses duplicate queries within a
render, so repeated widget reads are unaffected; only the distributed
snapshot is skipped, and only for requests that must never be shared
anyway.

Fixes emdash-cms#2785
@jakevis
jakevis force-pushed the fix/collection-edit-proxy branch from 3cf9236 to cd89ed1 Compare September 9, 2026 03:49
@jakevis

jakevis commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Sep 9, 2026
@pkg-pr-new

pkg-pr-new Bot commented Sep 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/auth-atproto

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

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

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

emdash

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

create-emdash

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

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

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

@emdash-cms/plugin-cli

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

@emdash-cms/plugin-types

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

@emdash-cms/registry-client

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

@emdash-cms/registry-lexicons

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

@emdash-cms/registry-moderation

npm i https://pkg.pr.new/@emdash-cms/registry-moderation@2970

@emdash-cms/registry-verification

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

@emdash-cms/sandbox-workerd

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

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-field-kit

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

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: cd89ed1

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@ascorbic
ascorbic merged commit f9ac286 into emdash-cms:main Sep 9, 2026
52 of 53 checks passed
@emdashbot emdashbot Bot mentioned this pull request Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getEmDashCollection always returns a no-op edit proxy, so visual editing never works on list pages

2 participants