Skip to content

fix(sections-editor): keep stored values on real conflicts and follow moved sections - #7918

Merged
viktormarinho merged 2 commits into
mainfrom
fix/cms-conflict-aware-merge
Oct 14, 2026
Merged

viktormarinho merged 2 commits into
mainfrom
fix/cms-conflict-aware-merge

Conversation

@viktormarinho

@viktormarinho viktormarinho commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What is this contribution about?

Follow-up to #7909. That PR stopped a stale section form from silently reverting changes published from another draft: when the stored section moved on, the editor merges the form's edits on top of it. The merge it uses in the editor still has three cases where the result surprises the user. This PR fixes them, plus one place that still failed outright.

What was still wrong

  1. A value both sides changed: the form won silently. If someone else changed the headline and I changed it too, mine was saved. The toast said my changes were applied on top of the latest version, which read as if nothing was lost, but the other value was gone.
  2. A section inserted above the open one: two sections got spliced together. Inline page sections are addressed by position. After someone inserted, removed, or moved a section above mine, the form's position pointed at a different section. The merge then applied my edits to it, mixing the two. Before fix(decofile): stop stale editor copies from reverting other drafts' block changes #7909, the form overwrote that section outright.
  3. A section whose type changed was merged anyway. This produced the new type with the old type's props.
  4. Saves outside the section form failed. Page name, path, SEO, and matcher edits use the cached block as their base. When the server refused one as stale, the user got "not saved" and the edit was lost, even when it touched a value nobody else had changed.

The fix

  • Merge rules (mergeBlockJson in @decocms/shared/decofile): the merge now takes the side to prefer and reports the JSON pointer of every value both sides changed. The draft sync keeps preferring the draft, so its behaviour is unchanged.
  • Section form (sections-editor.tsx, form-base.ts):
    • Edits to different values merge silently, as before.
    • A value both changed keeps the stored version. The rest of the edit is saved, and a warning names the fields that kept the stored value ("Changed while you were editing: headline. The latest version of those fields was kept, and the rest of your changes were saved."). The form shows the merged values.
    • If the page gained or lost sections and the section the form opened is found, unchanged, at exactly one other position, the form follows it there and saves at the new position. If the page has as many sections as before, the section at the form's position is treated as the form's own, edited in place; a page can repeat a section verbatim, and following the twin would write to the wrong one. If the count changed and the section can't be told apart, the form reloads.
    • If a section of a different type now sits at the form's position, the form reloads instead of merging, with a toast saying the last change was not saved.
  • Other saves (use-save-block.ts): a save built from the cache that the server refuses is replayed once on the fresh copy, when the two edits touched different values. On a real conflict it still fails, and the message now names the fields. The section form opts out with rebaseOnConflict: false because it resolves conflicts itself.

Why prefer the stored value in the editor

This matches what the previous admin did within one environment: its JSON Patch test operations refused a change to a value someone else had changed. The difference is that the previous admin then discarded the whole edit; here only the conflicting fields keep the stored value, and the rest is saved. Between drafts, the draft still wins per value (unchanged from #7909). A warning at publish time about what will be overwritten is left for a separate PR, because it needs UI in the publish dialog.

How did you verify your code works?

  • bun run verify (fmt, oxlint, knip, 10,933 unit tests) and bun run check pass.
  • New unit tests:
    • block-merge.test.ts: no conflicts reported for disjoint edits, pointer paths (including escaping), prefer: "theirs" keeping the stored value and the rest of the edit, whole-array conflict.
    • form-base.test.ts: sectionTypeChanged, findSectionMovedTo.
    • conflict-fields.test.ts: readable field names, 1-based positions, truncation.
  • New browser tests in site-editor-stale-form.spec.ts, run locally against the GitHub stub:
    • Same value changed by both: the stored headline stays, the form shows it, and the warning names "headline".
    • Section inserted above the open one: the edit lands on the section the form opened, at its new position, and the inserted section is untouched.
    • Identical twin sections, with someone else editing the open one in place: the edit stays on the open one and merges with theirs. A first version of this PR followed the untouched twin instead; this test reproduces that in the browser and now passes.
    • Renaming a page whose sections someone else changed: the first save gets a 409 and is replayed on the fresh page (asserted [409, 200]), and both changes are stored with no error toast.
  • The first three fail on main's editor code and pass with this change.
  • Related specs (site-editor-stale-form, decofile-api, fast-preview-git-sync, site-editor-breadcrumbs, cms-publish-surface): 33 passed locally.
  • Not run: the full e2e suite (CI will run it).

Screenshots/Demonstration

A value someone else also changed keeps the stored version, and the warning names it:

Warning naming the field that kept the stored value

How to Test

  1. Open a Fast Preview project in two browsers, A and B, on the same draft, and open the same section in both.
  2. In B, change the headline. In A, change the headline too.
    • Expected: A's form shows B's headline and a warning naming "headline".
  3. In B, insert a section above the one A has open. In A, edit a field.
    • Expected: the edit is saved on A's section, now one position down, and the inserted section is unchanged.
  4. In B, edit a section of a page. In A, rename that page.
    • Expected: both changes are saved and A sees no error.

Migration Notes

None.

Review Checklist

  • PR title is clear and descriptive
  • Changes are tested and working
  • Documentation is updated (if needed)
  • No breaking changes

… moved sections

The editor merged a stale form into the stored section with the form winning
every value both had changed, and could splice two sections together when one
was inserted above the open one. Make the merge conflict-aware:

- Edits to different values still merge silently.
- A value both changed keeps the stored version; the rest of the edit is saved
  and a warning names the fields that kept the stored value.
- When a section was inserted, removed, or moved above the open one, the form
  follows it to its new position and saves there; when the section at the
  form's position is a different type, the form reloads instead of merging.
- Saves built from the cache (page name/path/SEO, matchers, ...) that the
  server refuses as stale are replayed once on the fresh copy when the two
  edits touched different values, instead of failing.

mergeBlockJson takes the side to prefer and reports conflicting paths; the
draft sync keeps preferring the draft.
Following "the section the form opened, found unchanged elsewhere" misfired on
pages that repeat a section verbatim: when someone edited the open one in
place, its untouched twin matched, and the form's edit was written to the twin.
Only look for a moved section when the page gained or lost sections, accept a
single match, and reload the form when the match is ambiguous.
@viktormarinho
viktormarinho enabled auto-merge (squash) October 14, 2026 17:55
@viktormarinho
viktormarinho merged commit a593f2b into main Oct 14, 2026
33 checks passed
@viktormarinho
viktormarinho deleted the fix/cms-conflict-aware-merge branch October 14, 2026 18:01
decocms Bot pushed a commit that referenced this pull request Oct 14, 2026
PR: #7918 fix(sections-editor): keep stored values on real conflicts and follow moved sections
Bump type: patch

- decocms (apps/api/package.json): 4.482.3 -> 4.482.4
- @decocms/native (apps/native/package.json): 4.482.3 -> 4.482.4
- @decocms/e2e (packages/e2e/package.json): 1.110.2 -> 1.110.3
- @decocms/shared (packages/shared/package.json): 0.156.1 -> 0.156.2

Deploy-Scope: web
tlgimenes added a commit that referenced this pull request Oct 15, 2026
…ection

Brings in fold/v8-api, which now carries origin/main (114 commits),
including #7909 and #7918 (section forms start from a known version, saves
send `expect`, a stale save is refused with 409 and replayed or reloaded).

Conflicts resolved:
- use-save-block.ts: main's Fast Preview save (`base` -> `expect`, rebase
  on 409, BlockConflictError, no rollback on a conflict, `written`) moves
  into this branch's `writeLegacy`; the content-protocol path and SaveGuard
  stay as they were. `mutate`/`mutateAsync` keep main's `withBase` default
  and the hook keeps `reportError`.
- sections-editor.tsx: both form reloads stay (the content-epoch reload for
  discards/publishes and #7909's `reloadStaleForm`); main's form-base
  tracking, three-way merge, section following and retry-once are kept;
  failed saves use this branch's `reportError`.
- serve-save-error.ts: a BlockConflictError's own message (#7909's copy) is
  the toast headline on every backend, with no Details line.
- resolve-schema.ts and its cache test: #7899/#7903 were already
  cherry-picked here; this branch's lazy-block handling and A9 test stay.
- cms-header-actions.tsx / cms-panel-state.ts: main dropped
  cmsHeaderButtonLabels; the hosted header helpers stay.
- playwright.config.ts: both env additions (hosted env, GraphQL stub URL,
  BOARD_TRANSITION_SETTLE_SECONDS).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016ZsmzpZ2zahRBoATBb2tBu
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