Repository navigation
Add scalar list field support (BND-5037) - #13
Conversation
Studio sends a `field-update` with `isList: true` for scalar list fields (String/ID/Enumeration/Int/Float/Boolean/Date/DateTime lists), but withholds those updates unless the SDK announces `scalarListSync` in its ready message. No published SDK announces it, so list fields never update live. This ports the SDK half of the change, which was implemented against the copy of this SDK that still lives in the Hygraph monorepo and so was never released. - Announce `scalarListSync` in the ready message. It is not configurable: it states what this build can handle, not what the consumer wants. - Render a whole-list binding as its items joined with `, `, or per item when items are tagged `data-hygraph-list-index` (`listIndex` on `createPreviewAttributes`). - Refuse to write a list into an element that has child elements, so a `<ul>` of `<li>` items reports `preview:update-failed` instead of losing markup the SDK cannot rebuild. - Emit `preview:field-updated` once the built-in updater has applied a change, and `preview:update-failed` when it could not; the update detail now carries `componentChain`, `isList`, `fieldType` and `transformedValue`, so a consumer can re-render what the built-in updater deliberately leaves alone. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Found dogfooding this branch against local Studio: saving an entry makes Studio send two `updatedAt` messages inside the debounce window, and the first one - discarded in favour of the second - was reported to listeners as `preview:field-updated`. Nothing had reached the DOM, so a consumer re-rendering on that event re-renders from a value the page never received. ContentUpdater now marks a superseded update as such instead of returning a bare success, and Preview emits neither event for it; the update that does apply still reports for itself. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Dogfooded this branch against a real local Studio before asking for review: UMD build from the branch served to a fixture page, driven through the Studio content form on a live entry ( Handshake confirmed. The build announces 12 cases pass, including the ones that matter for existing consumers: single-field updates, component-chain disambiguation between sibling instances, the Click to Edit overlay round-trip ( One defect found, and it was mine — fixed in 13d0075: Saving makes Studio send two Two things for the reviewer, neither introduced here:
|
Why
Studio already sends
field-updatemessages withisList: truefor scalar list fields (String/ID/Enumeration/Int/Float/Boolean/Date/DateTime lists), and gates them on the SDK announcing ascalarListSynccapability — failing closed, because an SDK without list support writes the array straight into the bound element (destroying a<ul>'s<li>children, renderingInvalid Datefor a Date list).No published SDK announces that capability, so scalar list fields currently never update live for anyone. The SDK half of the feature was written against the older copy of this SDK that still lives in the Hygraph monorepo (
tools/preview-sdk, stuck at 0.2.0, not published), so it never shipped. This ports it here, translated onto the current API (Preview,createPreviewAttributes, nolocale).What
scalarListSyncin the ready message. Not configurable — it states what this build can handle, not what the consumer wants.,.data-hygraph-list-index(orlistIndexoncreatePreviewAttributes) and each item is patched individually.preview:update-failed, instead of destroying markup the SDK cannot rebuild.preview:field-updatedis now emitted once the built-in updater has applied a change (it previously emitted nothing),preview:update-failedwhen it could not. The detail carriescomponentChain,isList,fieldTypeandtransformedValue, so consumers can re-render what the built-in updater deliberately leaves alone (component arrays, list add/remove).isListon the field-update base, a scalar-list variant ofFieldUpdatewithScalarListValue,data-hygraph-list-indexonElementAttributes.agents.md.Verification
npm test— 51 passed (38 before, 13 added). Each new test was watched failing first.npm run type-check,npm run lint,npm run build— clean.Deliberately not ported
The monorepo copy also relaxed component-chain matching: it compares chains prefix-wise in both directions and always applies updates to untagged elements. That contradicts two behaviours this repo pins with tests (
updates only elements with exact component chain match,excludes elements without component chain when other elements have it), so it is left out of this PR. Worth deciding separately which semantics we want — an element tagged with a chain deeper than the one Studio reports is currently skipped.Follow-ups
data-hygraph-list-indexsection.tools/preview-sdkshould be deleted or stubbed with a pointer here, so the next SDK change does not land in the unpublished copy again.