Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit ab0e0fd

Browse files
fix(app-shell): take a served metadata draft as-is instead of spreading it over the published layer (objectui#10765) (#10775)
Fixes #10765 Clause-②: no — the Studio editor's draft rebuild; no declared surface moves ## What changed Every editor that rebuilt its draft as the served draft SPREAD over `layered.effective` now takes the served draft as-is and falls back to the baseline (`effective`, then `code`) only when no draft body was read (see H2 for what that covers). `effective` is the PUBLISHED layer and a spread cannot express deletion, so a key the author cleared in the draft came back from the published layer on the next refresh and the next save sent it again. Nine sites in three files of `@object-ui/app-shell`, one spelling each (`served draft ?? baseline`): - `ResourceEditPage.tsx` — the load effect (`rawInitial`), the post-save refresh in `doSave` (`rawFresh`), the post-publish refresh in `doPublish` (`rawFresh`; `config.toDraft` now runs there too, as the other two refreshes already did). - `StudioDesignSurface.tsx` — the Interfaces pillar's app load (`appDraft`), its surface-leaf load (`setDraft`), the Data pillar's object load (`setObjDraft`), the Automations pillar's flow load (`setDraft`). The triage named the surface-leaf site; the other three are the same spread in the same file, and the triage's rule is "no per-type exception". - `PackageOwdOverviewPanel.tsx` — the list load that derives each row's OWD values and the save that splices the edit into the object's body. Bounded in-place exemption, declared below. Three pin files, one changeset (`'@object-ui/app-shell': patch`), and a prose amendment to the pending objectui#10746 changeset, whose reach sentence this change made false (declared in Acceptance notes). No objectstack change. ## H1 — the premise: a served draft is always a whole document Answered from objectstack `origin/main` source (`packages/metadata-protocol/src/protocol.ts`, `packages/metadata-protocol/src/sys-metadata-repository.ts`, `packages/rest/src/rest-server.ts`), cited by symbol. A stock boot is NOT MEASURED: `/home/user/objectstack/node_modules` is empty in this container. - **The write stores the body raw.** `saveMetaItem` ends in `repo.put(ref, request.item, { state: mode === 'draft' ? 'draft' : 'active', … })`, and `SysMetadataRepository.put` stores `metadata: JSON.stringify(body)` with `body = spec ?? {}` — no read-modify-write against the existing row (the existing row is read only for the parent hash, the `skipped` short-circuit and, on a draft save, `package_id` inheritance). Before the put, `saveMetaItem` never merges the prior draft or the active row into the body. It subtracts only server-owned keys, in three strips: `stripReadDecorations` (the read-time decorations), `stripDerivedProvenance` (`_packageId` / `_packageVersion` / `_provenance`, which the read side recomputes) and `stripServedObjectColumns` (the system columns the server injects into a served object). None of the three reads another row. Everything else it does ADDS to the body or respells it, and the one pass that reads a stored row copies back redacted credential values only: `normalizeViewMetadata` grafts a view's missing `viewKind` / `object` / `label` from the registry baseline (`viewIdentityPatch`, "The overlay's own fields always win"); `withDeclaredPageTypeDefault` fills an absent page `type` with the schema's declared default; `carryForwardRedactedCredentials` restores a datasource's redacted credential values from the stored draft-or-active row; `graftNormalizedOperators` / `graftFoldedFormSections` rewrite spellings the schema already normalised. - **The draft read returns that row raw.** `getMetaItem` with `state: 'draft'` reads the `state: 'draft'` row (org-scoped, then env-wide; package-scoped, then global), `convertStoredItem`s it, and returns `decorateMetadataItem(type, governServedObject(type, item))`; when the row is absent it throws `NO_DRAFT` (404) — "Draft reads stop here — they intentionally do NOT fall through to the runtime registry". On this strict path `decorateMetadataItem` adds `_diagnostics` only; `_draft: true` is stamped on the `previewDrafts` arms, not here. `extractDraftBody` strips both on the client (the spec's `METADATA_READ_DECORATIONS`, through `stripReadDecorations`). - **`effective` never sees a draft.** `getMetaItemLayered` composes `effective` as `governServedObject(overlay ?? code)` where `overlay` is the `state: 'active'` row only. - **Publish promotes the draft raw.** `promoteDraft` reads the draft row and calls `this.put(ref, draft.body, { state: 'active', opType: 'publish', … })`, then drains the draft row. - **No partial-write door exists.** The REST save door is `PUT /meta/:type/:name` (`?mode=draft` maps to `{ mode: 'draft' }` and the body is passed as `item`); a grep of `packages/rest/src/rest-server.ts` for a PATCH route on `/meta` finds none. `@objectstack/client`'s `meta.saveItem(…, { mode: 'draft' })` sends the caller's body. `packages/cli/src` holds no `mode: 'draft'` writer. **Every writer of a `mode: 'draft'` body, enumerated (`git grep` over both trees at the stated refs, non-test source):** objectui (`63835d998f`): 1. `ResourceEditPage.doSave` — `itemToSave` = `config.fromDraft ? fromDraft(draft) : draft`: the whole editor draft (no type config defines `fromDraft` today). 2. `StudioDesignSurface` Interfaces pillar — `doCreateApp` (`buildAppSkeleton`, whole), surface `doSave` (`draft`, whole), `doNavSave` (`{ ...appDraft, navigation: cleanedNav }`, whole). 3. `StudioDesignSurface` Data pillar — object create (`buildObjectSkeleton`, whole), `doSave` (`objDraft`, whole), the field-order save (`{ ...objDraft, fields }`, whole). 4. `StudioDesignSurface` Automations pillar — flow create (`buildFlowSkeleton`, whole), `doSave` (`draft`, whole), `toggleEnabled` (`{ ...draft, status }`, whole); Access pillar — permission create (`buildPermissionSkeleton`, whole). 5. `ObjectHooksPanel` — `save` (`draft`, a whole hook item) and `addHook` (`fresh`, whole). 6. `PackageOwdOverviewPanel.doSave` — `next`, the whole object body with the two OWD keys set or deleted. 7. `PermissionMatrixEditor` — `mergePermissionSlice(base, payload, scope)` with `base = fresh.effective ?? payload`: a whole permission-set body (draft mode only when a `packageId` is bound). 8. `runtime-metadata-persistence.ts` — `persistRuntimeMetadata` / `createRuntimeMetadata` PUT the `body` their callers hold: the whole report from `ReportConfigPanel` through `ReportView.saveSchema`, the whole view from the runtime view persisters. 9. `@object-ui/data-objectstack` `ObjectStackAdapter.updateView(object, view, partial)` — the one API that TAKES a partial: it reads the pending draft (or the published view) and saves `mergeViewPatch(current, partial, …)` = `{ ...current, ...partial, name, object }`, a whole document. objectstack (`4df101c383`): 10. REST `PUT /meta/:type/:name?mode=draft` — passes the request body raw (above). 11. `ObjectStackClient.meta.saveItem` — the caller's body, raw. 12. `migrateStoredMetadata --apply` (`protocol.ts`, `source: 'migrate-stored'`) — re-saves the CONVERTED WHOLE stored row with `mode: state === 'draft' ? 'draft' : 'publish'`. No writer sends a subset of a document. The one caveat is not a writer but a door: any REST client can PUT a hand-written partial body with or without `?mode=draft`, and the server stores it as the whole draft or the whole published body alike — the editor then shows exactly what the server holds, which is the truthful reading. ⇒ Premise holds: **always full**; the "can be partial" stop in the triage did not fire, so no `needs_decision`. ## H2 — why the merge existed The comment at the load site said the spread kept "inherited fields like `type`" for ADR-0047 `visibleOn` predicates, treating the draft as a "partial draft overlay". A `type` is absent from a served draft only when the writer omitted it, and H1 shows no writer sends a subset: the editor's own saves carry `type` because the editor's draft was loaded from `effective` or the previous draft, both of which carry it, and for a page the server fills a missing `type` on the way in (`withDeclaredPageTypeDefault` in `saveMetaItem`) and on the way out (`convertStoredItem`). The inheritance the spread protected is inside the draft. The pins' CONTROL assertions read `type` back from the served draft at every step. **When the baseline is taken, as the code reads it.** Every site reads `client.getDraft(…).catch(() => null)`. `MetadataClient.getDraft` sits on `readItemResponse`, which returns `null` on a 404 (`NO_DRAFT`) and throws on any other non-OK answer; the `.catch` then folds a 403, a 5xx or a network failure into `null` too. So the baseline is taken when no draft body was READ, which covers "no draft exists" and also "the draft read failed". Base did the same at every site, and this change does not touch it. The hazard that leaves is named in Acceptance notes. ## H3 — the fix, per site | # | File · site | Before | After | |---|---|---|---| | 1 | `ResourceEditPage` load effect | `draftReal ? { ...baseline, ...draftReal } : baseline` | `draftReal ?? baseline` | | 2 | `ResourceEditPage.doSave` post-save refresh | `draftReal ? { ...freshBaseline, ...draftReal } : freshBaseline` | `draftReal ?? freshBaseline` | | 3 | `ResourceEditPage.doPublish` post-publish refresh | same spread, no `toDraft` | `draftReal ?? freshBaseline`, then `config.toDraft` | | 4 | `StudioDesignSurface` Interfaces — app load (`appDraft`) | `appDraftBody ? { ...eff, ...appDraftBody } : eff` | `appDraftBody ?? eff` | | 5 | `StudioDesignSurface` Interfaces — surface leaf load | `body ? { ...baseline, ...body } : baseline` | `body ?? baseline` | | 6 | `StudioDesignSurface` Data — object load (`setObjDraft`) | `draftBody ? { ...baseline, ...draftBody } : baseline` | `draftBody ?? baseline` | | 7 | `StudioDesignSurface` Automations — flow load | `draftBody ? { ...baseline, ...draftBody } : baseline` | `draftBody ?? baseline` | | 8 | `PackageOwdOverviewPanel` list load (`body`) | `draftBody ? { ...baseline, ...draftBody } : baseline` | `draftBody ?? baseline` | | 9 | `PackageOwdOverviewPanel.doSave` (`next`) | `{ ...baseline, ...(draftBody ?? {}) }` | `{ ...(draftBody ?? baseline) }` | `config.toDraft` still runs on whatever is taken at sites 1 and 2, and now at 3; it is inert today (no registered type config defines `toDraft` / `fromDraft` — the `registry.ts` interface declares them, `builtinComponents.tsx` states the view previews read `draft.config` directly and use none). Also checked, unchanged: `EmbeddedItemEditor.doSave` reads `layered.effective ?? layered.code` ALONE, splices the embedded item in and saves in publish mode — no draft is spread. `ResourceEditPage.doReset` and `doDiscardDraft` read the baseline alone after deleting the row — correct, unchanged. ## H4 — edges - **A type with no draft**: baseline, unchanged (pinned: EDGE / CONTROL in the `ResourceEditPage` file and the Interfaces CONTROL in the design-surface file — `toStrictEqual(published)`). - **First draft save of a never-drafted item**: the draft PUT is the whole `itemToSave`, and the refresh shows exactly that (pinned). - **A draft written by an older client or server that was partial**: the server cannot compose one (H1) and no writer in either tree's history reachable here sends one; a hand-written partial REST PUT stores a partial DRAFT or a partial PUBLISHED body alike, and the editor now shows what the server holds. NOT MEASURED against historical databases. - **Publish**: the promoted body is the draft raw (`promoteDraft` → `put(ref, draft.body, { state: 'active' })`); the triage's checklist item ("the published body lacks the cleared key") is pinned in both `ResourceEditPage` cases against the server double. ## Pins and ablations Three pin files (10 tests), all green on head `85f1b9e91a` (re-run this round under the verify lock: `Test Files 3 passed (3)`, `Tests 10 passed (10)`, `VERDICT command-exit 0`); 7 red on base with the three source files at `63835d998f` and the pin files present (the 3 that stay green are the controls). The base leg and the ablations below were measured at `5f3b9c73fd`; the round-2 commit `85f1b9e91a` changes comments and changeset prose only (a grep of its `.ts`/`.tsx` hunks for any changed line that is not a comment answers none), so no statement they read moved. - `ResourceEditPage.servedDraftTakenAsIs-10765.test.tsx` (4): mounts the REAL `MetadataResourceEditPage` with `registerBuiltinInspectors()` so the REAL `ReportDefaultInspector` type picker is the producer; a server double stores draft rows raw, serves `effective` as the active row only, promotes on publish, throws `NO_DRAFT` when no row. THE TRIAGE PIN: bound published matrix report → pick "Joined" → first PUT clean → post-save refresh has none of the six keys under `type: 'joined'` → an unrelated edit's second PUT has none → Publish → published body and post-publish editor draft have none. GENERIC: a published page's `description` deleted in the draft stays deleted on load, across the next save and refresh, and through publish, with `type` as the CONTROL. Two EDGE / CONTROL cases (no draft; first draft save is the whole document). - `StudioDesignSurface.servedDraftTakenAsIs-10765.test.tsx` (4): `InterfacesPillar` (app `label` deleted in the draft → heading reads `acme_app · Navigation`; page `description` deleted → the canvas draft lacks it), `DataPillar` (object `sharingModel` set back to unset → Settings shows unset), `AutomationsPillar` (flow `description` deleted → canvas draft lacks it, and the enable switch's save carries the draft alone). Plus the Interfaces CONTROL. - `PackageOwdOverviewPanel.servedDraftTakenAsIs-10765.test.tsx` (2): LIST LOAD (a cleared model reads unset) and SAVE (an internal-only edit does not resurrect the published `externalSharingModel` or `description`). Base leg, quoted: `Tests 7 failed | 3 passed (10)`; `AssertionError: after the post-save refresh the editor draft has no dataset: expected { name: 'pipeline', …(8) } to not have property "dataset"`; `expected { name: 'home', …(5) } to not have property "description"`; `expected 'private' to be ''`; `Unable to find an element with the text: acme_app · Navigation`. Restore proven: `git diff HEAD` empty, each path's blob equal to HEAD. Per-site ablations on the committed head through objectstack's `scripts/ablation-replace.mjs` (anchor hits exactly once, blob change proven, restore proven per leg, `diff-HEAD-lines=0` after each), prediction written before each run: | Site | Mutation | Predicted red | Observed | |---|---|---|---| | 1 load | `draftReal ?? baseline` → spread | GENERIC | `1 failed | 3 passed` — GENERIC (load: `description` back) ✔ | | 2 post-save | `draftReal ?? freshBaseline` (save) → spread | TRIAGE, GENERIC | `2 failed | 2 passed` ✔ | | 3 post-publish | `draftReal ?? freshBaseline` (publish) → spread | none | `4 passed` — none, as predicted (see Acceptance notes) | | 4 app | `appDraftBody ?? eff` → spread | Interfaces (heading) | `1 failed | 3 passed` — `Unable to find … acme_app · Navigation` ✔ | | 5 surface | `body ?? baseline` → spread | Interfaces (canvas) | `1 failed | 3 passed` — `not to have property "description"` ✔ | | 6 object | `setObjDraft(draftBody ?? baseline)` → spread | Data | `1 failed | 3 passed` — `expected 'private' to be ''` ✔ | | 7 flow | `setDraft(draftBody ?? baseline)` → spread | Automations | `1 failed | 3 passed` — `not to have property "description"` ✔ | | 8 OWD list | `body = draftBody ?? baseline` → spread | LIST LOAD | `2 failed (2)` — LIST LOAD and SAVE: MORE than predicted; the list-load merge also feeds the row's `external` edit, so the save wrote the resurrected `externalSharingModel` | | 9 OWD save | `{ ...(draftBody ?? baseline) }` → spread | SAVE | `1 failed | 1 passed` ✔ | Direction observed as predicted at eight sites; site 8 reddened one assertion more than predicted (reported as observed); site 3 reddened nothing, as predicted. ## Gates (local; objectui has no `dispatch-gates.mjs` — derived from `package.json` and `.github/workflows`) Round 2, at head `85f1b9e91a`, run after the final commit: - vitest, the three pin files, under the verify lock: `Test Files 3 passed (3)`, `Tests 10 passed (10)`, `VERDICT command-exit 0`. - `node scripts/check-changeset-presence.mjs`: exit 0 — ✅ "6 source file(s) of 1 released package(s) changed, and this change declares 1 changeset(s): .changeset/10765-draft-merge-deletion.md". - `node scripts/check-changeset-no-major.mjs`: exit 0 — ✅ "No changeset declares a `major` bump." - `node scripts/check-changeset-claims.mjs`: exit 0 (report-only). It names one pending changeset, `6681-declared-lazy-marketplace-routes.md`, for spelling `StudioDesignSurface.tsx`; that is a chunking claim, and this branch changes no import there. - `node scripts/check-changeset-overwrite.mjs`: exit 0 (report-only). It reports `M .changeset/10746-joined-report-clears-binding.md`, declared `@object-ui/app-shell: patch` at base and now: the intended prose correction declared in Acceptance notes (the gate's own case 2). - `pnpm check:pending-changeset-literals`: exit 0 — ✅ "No test source names a pending changeset." - `pnpm check:new-line-citations`: exit 0 — `VERDICT new-cross-file-line-citations: 0 new citation(s), enforcement report-only -> exit 0`. - `pnpm check:control-bytes`: exit 0 — ✅ "OK (scanned 8957 tracked text file(s); skipped 85 binary)". The role file's control-byte grep over the four files this round edits: no match. - `node scripts/check-governed-queue-guard.mjs --test` over the branch's eight paths: ✅ NOT GOVERNED. Round 1, at `5f3b9c73fd`, not re-run: round 2 changes comments and changeset prose only. - ① closure build `turbo run build --filter='@object-ui/app-shell^...' --concurrency=2` under the verify lock: `Tasks: 28 successful, 28 total`, `VERDICT command-exit 0`. - ② `pnpm --filter @object-ui/app-shell type-check` (`tsc --noEmit && tsc -p tsconfig.test.json`): `VERDICT command-exit 0`; `tsc -p tsconfig.test.json --listFiles` lists the three pin files (3 hits among 4677 files). - ② sibling suites (every `ResourceEditPage.*`, `PackageOwdOverviewPanel*`, `ObjectSettingsPanel.owdAgreement`, `StudioDesignSurface.*`, `DataPillar.*`, `ObjectHooksPanel.*`, `ReportDefaultInspector.*` test): `Test Files 57 passed (57) · Tests 271 passed (271)`, `VERDICT command-exit 0`. - `pnpm check:test-path-roots`, `pnpm check:vi-mock-specifiers`, `pnpm check:vi-mock-inherit`, `pnpm check:vi-mock-override-shape`: ✅ OK each. - eslint with the app-shell package config on the six touched `.tsx` files: exit 0, 0 errors, 76 pre-existing warnings, 0 of them on a line this branch changed (checked against the committed hunks). NOT MEASURED locally, CI-owned: `pnpm lint` (repo-wide), the test shards, `Build & E2E`, `check:i18n-*` (no `t()` key added or changed), `Governed Surface Queue Guard`. CI on `85f1b9e91a` was still running at the report read (every completed run a success or an expected skip); its converged state is the seat's reading. ## Serial Branch fast-forwarded to `63835d998f` (PR objectui#10762 landed) before the first edit, so the pins use its `commitType` as the real producer. Re-derived at round 2 against a fresh `origin/main`, fetched into a private ref: `17b323e5ca`, +4 over BASE (objectui#10754, objectui#10766, objectui#10763, objectui#10774). `git diff --stat 63835d9 17b323e` over the branch's eight paths is empty, and `git merge-tree --write-tree HEAD 17b323e` exits 0, clean, tree `fcd7226887`. No merge commit needed. Open PRs were not re-read this round; the seat's review read 10 and found none on `ResourceEditPage.tsx`, `StudioDesignSurface.tsx`, `EmbeddedItemEditor.tsx`, `PackageOwdOverviewPanel.tsx` or `PermissionMatrixEditor.tsx`. ## Acceptance notes - **Amends another card's pending changeset.** `.changeset/10746-joined-report-clears-binding.md` (objectui#10746, pending, same release) ended with a reach sentence this change made false: that a report whose PUBLISHED version was bound gets the cleared keys back in the draft after the first draft save until publish, through the host's draft-over-baseline merge (objectui#10765). Its sentences are now scoped "At this change", and a `⚠️ **Dated note, 2026-09-27 — that merge has since been removed — objectui#10765.**` in the objectui#10156 / objectui#10392 form states what holds now: the clear holds across the refresh after the save and through publish, because the editor takes a served draft as-is; a report already saved `joined` with stale keys is still not repaired on load, and the author deletes them from the JSON tab. The frontmatter is byte-identical: md5 of its three lines is `4e8ce55021fe3b14329c8b4cb3f9f354` at base `63835d998f`, at `5f3b9c73fd` and at `85f1b9e91a`. `check-changeset-overwrite` reports the file as modified; that is this intended correction. The objectui#10765 changeset gains one sentence naming the reach limit it removes. - **Pending-changeset sweep** (`git grep` of `.changeset/*.md` at fresh main `17b323e5ca` and at this head, for `layered.effective`, `draft-over`, `spread over`, `resurrect`, `objectui#10765` and `published layer`). Outside the objectui#10746 and objectui#10765 files the only hits are "resurrect" in four unrelated senses: `4919-retire-mobile-overrides.md` (a declaration), `6799-authored-columns-fls.md` (a grid column), `7499-gantt-non-axis-floors-omitted.md` (a gantt config) and `active-org-clear-removal-failure-5731.md` (a storage entry). None is falsified. A wider read for draft-over-baseline wording found `7603-resource-edit-read-decoration-strip.md` and `8181-draft-envelope-read-decoration-strip.md`. Both describe the merge in the past tense, as the state before their change. 7603's "the chokepoint all three merge sites go through" still holds of its subject, since all three sites still go through `extractDraftBody`; "merge sites" is that change's label. Nothing else needed reconciling. - **Stale comments, comment-only.** Fixed the two the review named: the Data pillar's projection-baseline comment in `StudioDesignSurface.tsx` and the `OwdRow` docblock in `PackageOwdOverviewPanel.tsx`. Fixed two more in `PackageOwdOverviewPanel.tsx` with the same stale wording: the list-load comment ("merged body (layered ∪ its draft)") and the save comment ("fresh merged body"). The file header's "(published ∪ pending drafts, the same merge the pillars do)" is about which OBJECTS are listed, a union of lists, so it stays. - **Pre-existing hazard, not this card's (see H2).** The `.catch(() => null)` on every draft read folds a failed read (403, 5xx, network) into "no draft", so the site shows the published baseline as the editable draft. The next save then writes that baseline-derived body as the draft, whether it is manual or the metadata-admin auto-save after an edit, and it replaces the pending draft the failed read never fetched. Base had the same shape at every site; this change neither adds nor removes it. Not filed. carrier: none. - **Bounded in-place exemption, declared**: `PackageOwdOverviewPanel.tsx` was not in the dispatch's file surface. Same defect class (a served object draft spread over `effective`), mechanical fix in the pinned shape, no other claim on the file (open-PR file lists read), same gate family (app-shell vitest / type-check / changeset), no new verification surface. Pinned with two red-on-base assertions; the file surface is stated here. - **Site 3 (post-publish)**: changed for the triage's "same rule at every site". Its ablation reddens nothing, as predicted: today's server drains the draft row on publish (`promoteDraft` → `dropPromotedDraftRow`), so `getDraft` answers `NO_DRAFT` after a publish and the spread had no draft to resurrect from; a draft that survives (a drain failure, or an autosave racing the publish) is a whole document equal to or newer than the promoted body. The spread there was inert in practice, not wrong — and it is now the same spelling as the other two refreshes. - **`config.toDraft` on the post-publish refresh**: added for uniformity; inert today (no type config defines the hook). - Observation, not filed (read-only inference, no reproduction): `PermissionMatrixEditor`'s package-scoped save merges the edited slice into `fresh.effective` (the PUBLISHED body) and never reads the pending draft, so a slice save could overwrite other pending draft edits of the same permission set. Different mechanism from this card's. carrier: none. - Observation, not filed: `EmbeddedItemEditor` reads the baseline alone and saves in publish mode (no `mode: 'draft'`), by design of the embedded flow; noted because the dispatch asked. - The triage's P1 checklist item (`studio-authoring.draft-publish-lifecycle`) owes an editor-driven step (clear a key over a published version, save, refresh, publish); that checklist lives in objectstack and is not touched here. --- _Generated by [Claude Code](https://claude.ai/code/session_014mXUNuFomfj24w7s1pZzhN)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent d89492c commit ab0e0fd

8 files changed

Lines changed: 805 additions & 38 deletions

‎.changeset/10746-joined-report-clears-binding.md‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ unbound report's switch stays the one-key patch it always was. `runtimeFilter` a
2323
`drilldown` are kept: the joined branch reads both. Switching between two non-joined
2424
types keeps the binding; switching away from `joined` restores nothing — the author
2525
re-binds. `blocks` is never touched. The clear holds for the patch and for the save that
26-
follows it. The metadata-admin editor rebuilds its draft as the served draft spread over
27-
`layered.effective` (on load, after each save and after publish), and `effective` is the
28-
published layer, so a report whose PUBLISHED version was bound gets those keys back in the
29-
draft after the first draft save until it is published, and a report already saved `joined`
30-
with stale keys is not repaired on load. Both are the host's draft-over-baseline merge,
31-
objectui#10765.
26+
follows it. At this change the metadata-admin editor rebuilds its draft as the served draft
27+
spread over `layered.effective` (on load, after each save and after publish), and
28+
`effective` is the published layer, so a report whose PUBLISHED version was bound gets those
29+
keys back in the draft after the first draft save until it is published, and a report already
30+
saved `joined` with stale keys is not repaired on load. Both are the host's
31+
draft-over-baseline merge, objectui#10765.
32+
33+
⚠️ **Dated note, 2026-09-27 — that merge has since been removed — objectui#10765.** Later in
34+
this same release the metadata-admin editor takes a served draft as-is instead of spreading
35+
it over the published layer, so the clear holds across the refresh after the save and through
36+
publish. A report already saved `joined` with stale keys is still not repaired on load; the
37+
author deletes them from the JSON tab. The rest of this entry is kept as the reading of this
38+
change; the objectui#10765 entry states what the editors now do.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(app-shell): the metadata editors take a served draft as-is instead of spreading it over the published layer (objectui#10765)
6+
7+
The metadata-admin editor (`ResourceEditPage`) rebuilt its draft as the served draft spread
8+
over `layered.effective` — on load, after every draft save and after publish — and the Studio
9+
design surface did the same when it opened an app, a surface, an object or a flow, as did the
10+
package OWD overview when it read and re-saved an object's draft. `effective` is the PUBLISHED
11+
layer, and a spread cannot express deletion: a key the author cleared in the draft (the report
12+
inspector's joined clear of `dataset` / `values` / `rows` / `columns` / `chart` / `order`, an OWD
13+
model set back to unset, any key deleted from the JSON tab) was absent from the first draft PUT,
14+
came back into the editor from the published layer on the refresh after that save, invisibly,
15+
and the next save or publish sent it again.
16+
17+
The spread existed for a partial draft overlay that never reaches these editors: the server
18+
(`metadata-protocol`) stores a `?mode=draft` body raw and its `?state=draft` read returns that
19+
row raw, and every draft writer sends a whole document. So each site now takes the served draft
20+
as-is when there is one and falls back to `effective` (then `code`) only when no draft exists;
21+
the inherited `type` the spread was protecting is already inside the draft. `config.toDraft`
22+
still normalises whatever is taken, now on the post-publish refresh as well. This removes the
23+
reach limit the objectui#10746 entry states — a bound published report getting its cleared
24+
keys back after the first draft save; a report already saved `joined` with stale keys is still
25+
not repaired on load, and the author deletes them from the JSON tab.

‎packages/app-shell/src/views/metadata-admin/ResourceEditPage.servedDraftTakenAsIs-10765.test.tsx‎

Lines changed: 357 additions & 0 deletions
Large diffs are not rendered by default.

‎packages/app-shell/src/views/metadata-admin/ResourceEditPage.tsx‎

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,16 +1044,16 @@ function MetadataResourceEditPageImpl({
10441044
// Prefer the pending draft as the editing baseline — the
10451045
// operator is mid-flight on this item and should see their
10461046
// own in-progress state, not the last published version.
1047-
// A pending draft overlay can carry only the edited fields, so using
1048-
// it wholesale would drop inherited fields that were never touched —
1049-
// notably `type`, which section-level `visibleOn` predicates depend on
1050-
// (ADR-0047 hides Data Context / Layout when `data.type == 'list'`).
1051-
// Merge the draft over the effective baseline so those fields survive;
1052-
// the draft still wins for anything it does carry.
1047+
// A served draft is the WHOLE document (objectui#10765): the server
1048+
// stores a `?mode=draft` body raw and its `?state=draft` read returns
1049+
// that row raw, and every writer of a draft sends a full document —
1050+
// so `type` and every other inherited field are already inside it.
1051+
// ⛔ Never spread the draft over `effective`: a spread cannot express
1052+
// deletion, so a key the author cleared came back from the PUBLISHED
1053+
// layer on every reload and the next save sent it again. The
1054+
// baseline is only for an item that has no pending draft at all.
10531055
const baseline = (lay.effective ?? lay.code ?? {}) as Record<string, unknown>;
1054-
const rawInitial: Record<string, unknown> = draftReal
1055-
? { ...baseline, ...(draftReal as Record<string, unknown>) }
1056-
: baseline;
1056+
const rawInitial: Record<string, unknown> = draftReal ?? baseline;
10571057
// Normalise the wire shape into the editor's draft shape (e.g.
10581058
// `view` unwraps an expanded ViewItem's `config` into a
10591059
// `{ list | form }` family key). No-op for types without a hook.
@@ -1513,12 +1513,14 @@ function MetadataResourceEditPageImpl({
15131513
setLayered(lay);
15141514
const draftReal = extractDraftBody(draftResp);
15151515
setHasDraft(!!draftReal);
1516-
// Merge the draft over the effective baseline (see the load effect):
1517-
// a partial draft overlay must not drop inherited fields like `type`.
1516+
// The served draft is the whole document the save just stored (see the
1517+
// load effect, objectui#10765): take it as-is. ⛔ Not spread over
1518+
// `effective` — that is the PUBLISHED layer, and a spread would bring a
1519+
// key this save deleted straight back into the editor, invisibly, for
1520+
// the next save to send. The baseline is only for a save that left no
1521+
// draft row to read back.
15181522
const freshBaseline = (lay.effective ?? itemToSave) as Record<string, unknown>;
1519-
const rawFresh: Record<string, unknown> = draftReal
1520-
? { ...freshBaseline, ...(draftReal as Record<string, unknown>) }
1521-
: freshBaseline;
1523+
const rawFresh: Record<string, unknown> = draftReal ?? freshBaseline;
15221524
// Re-normalise the refreshed wire shape so the editor keeps showing
15231525
// the canonical draft shape after a save (e.g. the backend re-expands
15241526
// a view into the ViewItem `config` wrapper).
@@ -1690,13 +1692,15 @@ function MetadataResourceEditPageImpl({
16901692
setLayered(lay);
16911693
const draftReal = extractDraftBody(draftResp);
16921694
setHasDraft(!!draftReal);
1693-
// Merge the draft over the effective baseline so a partial draft overlay
1694-
// doesn't drop inherited fields like `type` (section visibleOn depends
1695-
// on it — ADR-0047).
1695+
// After a publish the promoted body IS `effective` and the draft row is
1696+
// normally gone; a draft that does remain is a whole document and is
1697+
// taken as-is (objectui#10765). ⛔ Not spread over `effective`: the
1698+
// spread cannot express deletion and would resurrect a published key
1699+
// the draft had cleared.
16961700
const freshBaseline = (lay.effective ?? draft) as Record<string, unknown>;
1697-
const fresh: Record<string, unknown> = draftReal
1698-
? { ...freshBaseline, ...(draftReal as Record<string, unknown>) }
1699-
: freshBaseline;
1701+
const rawFresh: Record<string, unknown> = draftReal ?? freshBaseline;
1702+
// Same wire-to-editor normalisation the load and save refreshes apply.
1703+
const fresh = config.toDraft ? config.toDraft(rawFresh) : rawFresh;
17001704
setDraft(fresh);
17011705
draftSnapshotRef.current = fresh;
17021706
} catch (err: any) {
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectui#10765 — the package OWD overview reads and re-saves an object's
5+
* pending draft AS-IS. It never spreads the draft over `layered.effective`.
6+
*
7+
* `effective` is the PUBLISHED layer and a spread cannot express deletion, so
8+
* an OWD model the author had set back to unset in the draft (a real authored
9+
* state — `PackageOwdOverviewPanel.test.tsx` pins that clearing a model DROPS
10+
* the key) read as still set from the published row, and the next OWD save
11+
* wrote that published value, plus every other key the draft had deleted,
12+
* back into the object's draft. Same host-level cause as the metadata-admin
13+
* editor's merge; the panel has two sites — the list load that derives each
14+
* row's values and the save that splices the edit into the body — and both
15+
* are pinned here, one assertion each, red on base.
16+
*
17+
* The client is a server double: `effective` is the active row, `getDraft`
18+
* serves the stored draft row raw, `save` records the wire body.
19+
*/
20+
21+
import '@testing-library/jest-dom/vitest';
22+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
23+
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
24+
import React from 'react';
25+
26+
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
27+
28+
import { PackageOwdOverviewPanel } from './PackageOwdOverviewPanel';
29+
30+
/** The published object: both OWD models set, plus a description. */
31+
const PUBLISHED = {
32+
name: 'crm_contact',
33+
label: 'Contact',
34+
sharingModel: 'private',
35+
externalSharingModel: 'private',
36+
description: 'published description — the draft deleted this key',
37+
};
38+
39+
/** The pending draft as the author left it: both models unset, description deleted. */
40+
const SERVED_DRAFT = {
41+
name: 'crm_contact',
42+
label: 'Contact',
43+
_diagnostics: { valid: true, errors: [] },
44+
};
45+
46+
const saved: Array<{ name: string; body: Record<string, unknown>; opts: Record<string, unknown> | undefined }> = [];
47+
48+
function makeClient() {
49+
return {
50+
list: async (type: string) => (type === 'object' ? [{ name: PUBLISHED.name, label: PUBLISHED.label }] : []),
51+
listDrafts: async () => [],
52+
layered: async (_t: string, name: string) => ({
53+
effective: name === PUBLISHED.name ? PUBLISHED : {},
54+
code: null,
55+
}),
56+
getDraft: async (_t: string, name: string) =>
57+
name === PUBLISHED.name ? { type: 'object', name, item: SERVED_DRAFT } : null,
58+
save: async (_t: string, name: string, body: Record<string, unknown>, opts?: Record<string, unknown>) => {
59+
saved.push({ name, body: JSON.parse(JSON.stringify(body)) as Record<string, unknown>, opts });
60+
return body;
61+
},
62+
} as any;
63+
}
64+
65+
beforeEach(() => {
66+
saved.length = 0;
67+
Element.prototype.scrollIntoView = vi.fn();
68+
});
69+
afterEach(() => {
70+
cleanup();
71+
vi.clearAllMocks();
72+
});
73+
74+
describe('PackageOwdOverviewPanel — the pending draft is read and re-saved as-is (objectui#10765)', () => {
75+
it('LIST LOAD: a model the draft cleared reads as unset, not as the published value', async () => {
76+
render(<PackageOwdOverviewPanel client={makeClient()} packageId="com.example.showcase" locale="en-US" />);
77+
await screen.findByTestId('owd-row-crm_contact');
78+
79+
const internal = screen.getByTestId('owd-internal-crm_contact') as HTMLSelectElement;
80+
// Red on base: the spread over `effective` showed `private` from the published row.
81+
expect(internal.value).toBe('');
82+
});
83+
84+
it('SAVE: an edit lands on the draft alone — the published model and description the draft deleted do not come back', async () => {
85+
render(<PackageOwdOverviewPanel client={makeClient()} packageId="com.example.showcase" locale="en-US" />);
86+
await screen.findByTestId('owd-row-crm_contact');
87+
88+
fireEvent.change(screen.getByTestId('owd-internal-crm_contact'), { target: { value: 'public_read' } });
89+
fireEvent.click(screen.getByTestId('owd-save'));
90+
91+
await waitFor(() => expect(saved).toHaveLength(1));
92+
const { name, body, opts } = saved[0]!;
93+
expect(name).toBe('crm_contact');
94+
expect(opts).toMatchObject({ mode: 'draft', packageId: 'com.example.showcase' });
95+
expect(body.sharingModel).toBe('public_read');
96+
// Red on base: both came back from `effective` through the spread.
97+
expect(body).not.toHaveProperty('externalSharingModel');
98+
expect(body).not.toHaveProperty('description');
99+
// The draft's own keys travel; the read decorations do not (objectui#8181).
100+
expect(body.label).toBe('Contact');
101+
expect(body).not.toHaveProperty('_diagnostics');
102+
});
103+
});

‎packages/app-shell/src/views/studio-design/PackageOwdOverviewPanel.tsx‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ import { isExternalWider, deriveMasterObject } from './owd-sharing.js';
3939
import { toast } from 'sonner';
4040

4141

42-
/** A single object's loaded OWD baseline (already merged over any pending draft). */
42+
/**
43+
* A single object's loaded OWD values — read from its pending draft as-is when
44+
* one exists, else from its layered baseline (objectui#10765).
45+
*/
4346
interface OwdRow {
4447
name: string;
4548
label: string;
@@ -143,8 +146,9 @@ export function PackageOwdOverviewPanel({
143146

144147
// The list row carries `sharingModel` but not reliably `fields` (needed
145148
// for the master link), and never the pending-draft value — so read each
146-
// object's merged body (layered ∪ its draft), exactly as the per-object
147-
// Settings tab does, and derive every column from that one source.
149+
// object's body (its pending draft as-is, else its layered baseline),
150+
// exactly as the per-object Settings tab does, and derive every column
151+
// from that one source.
148152
const built = await Promise.all(
149153
names.map(async (name): Promise<OwdRow> => {
150154
const [layRaw, draftResp] = await Promise.all([
@@ -154,7 +158,11 @@ export function PackageOwdOverviewPanel({
154158
const lay = (layRaw ?? {}) as { effective?: Record<string, unknown>; code?: Record<string, unknown> };
155159
const baseline = (lay.effective ?? lay.code ?? {}) as Record<string, unknown>;
156160
const draftBody = extractDraftBody(draftResp);
157-
const body = draftBody ? { ...baseline, ...draftBody } : baseline;
161+
// The pending draft is the whole document: read it as-is, and the
162+
// published baseline only when no draft exists (objectui#10765). A
163+
// spread over `effective` showed a model the draft had cleared as
164+
// still set, from the published layer.
165+
const body = draftBody ?? baseline;
158166
const internal = typeof body.sharingModel === 'string' ? body.sharingModel : '';
159167
return {
160168
name,
@@ -233,7 +241,7 @@ export function PackageOwdOverviewPanel({
233241
setSaveError(null);
234242
try {
235243
// Each changed row lands as that object's package-scoped DRAFT: read the
236-
// fresh merged body, apply just the OWD pair (unset → drop the key), and
244+
// fresh body (below), apply just the OWD pair (unset → drop the key), and
237245
// save. Identical to the per-object Settings write, N times — publish
238246
// then goes through the same package security-domain gate unchanged.
239247
for (const s of changed) {
@@ -244,7 +252,11 @@ export function PackageOwdOverviewPanel({
244252
const lay = (layRaw ?? {}) as { effective?: Record<string, unknown>; code?: Record<string, unknown> };
245253
const baseline = (lay.effective ?? lay.code ?? {}) as Record<string, unknown>;
246254
const draftBody = extractDraftBody(draftResp);
247-
const next: Record<string, unknown> = { ...baseline, ...(draftBody ?? {}) };
255+
// The pending draft is the whole document — the edit lands on it as-is,
256+
// and on the published baseline only when no draft exists
257+
// (objectui#10765): a spread over `effective` would put back every key
258+
// the draft had deleted and save them again as this object's draft.
259+
const next: Record<string, unknown> = { ...(draftBody ?? baseline) };
248260
if (s.edit.internal) next.sharingModel = s.edit.internal;
249261
else delete next.sharingModel;
250262
if (s.edit.external) next.externalSharingModel = s.edit.external;

0 commit comments

Comments
 (0)