Repository navigation
feat: let slice field commands target the items zone - #463
Conversation
Slices upgraded from the Legacy Builder keep their repeatable fields in the deprecated items zone. The field commands could not reach them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L1dGD8SwrKjWRKbjezoBWe
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L1dGD8SwrKjWRKbjezoBWe
Slice field commands now take a boolean --legacy-items-zone flag instead of --zone. Without the flag, commands edit the slice fields as on main. Remove the enumOption helper because nothing else uses it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L1dGD8SwrKjWRKbjezoBWe
jomifepe
left a comment
There was a problem hiding this comment.
LGTM! Left one suggestion 💡
| if (!variation) throw new SliceVariationNotFoundError(variationId, slice.id); | ||
| if (items) { | ||
| if (!variation.items || Object.keys(variation.items).length === 0) { | ||
| throw new SliceItemsNotFoundError(variationId, slice.id); |
There was a problem hiding this comment.
primary
This throws as soon as items is empty. field edit can't change a field's type, so changing the type of the only items field means remove, then add:
$ prismic field remove image --from-slice hero --legacy-items-zone
Field removed: image
$ prismic field add link image --to-slice hero --legacy-items-zone
Variation "default" of slice "hero" has no legacy items zone. Add fields to the slice instead.
An agent that follows this message adds the field to primary. That turns a per-item field into a per-slice field, and existing item content no longer maps to it. The Type Builder keeps the empty list for the current mount for exactly this case. The CLI keeps no state between commands, so it can't do the same.
Hiding an empty zone is the right rule. upgrade-legacy writes items: {} on every variation, so checking whether the key exists would not work.
Suggestion: Make the dead end visible before users hit it.
- In
field remove, when the removed field was the last one in the items zone, print a warning that the zone can no longer be edited, and that replacement fields must be added before the last one is removed. - Reword the error so it doesn't send people to
primarywithout context, e.g. "…has no legacy items zone. To add repeatable fields, add a repeatable group to the slice." That wording also keeps CLI flag names out ofsrc/lib.
There was a problem hiding this comment.
Reply from Claude, working with Angelo on this PR.
Thanks! The empty-zone-is-no-zone behaviour is kept on purpose: once the last items field is removed, the legacy zone is retired, and new repeatable content belongs in a repeatable group.
The error is updated in 40b424c and 6c5d6c3. SliceItemsNotFoundError in src/lib now only says the variation has no legacy items zone and that repeatable fields go in a repeatable group, with no CLI syntax. The CLI hint is added one layer up in src/fields.ts, in one small wrapper around resolveSliceFieldContainer that all field commands use (add, edit, remove, reorder):
Variation "default" of slice "hero" has no legacy items zone. To add repeatable fields, add a repeatable group to the slice.
Hint: prismic field add group items --to-slice hero
Then add fields to the group: prismic field add text items.<field_id> --to-slice hero
Generated by Claude Code
The error for a missing legacy items zone told users to add fields to the slice. That did not tell them how to keep repeatable content. The message now tells them to add a repeatable group to the slice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L1dGD8k3F268SphC2JdpP7
When a field command uses --legacy-items-zone on a slice variation that has no legacy items zone, the error now shows the commands to run. The hint tells the user to add a group to the slice, and then to add fields to that group with dot notation. The slice ID is filled in. The --variation flag is added when the variation is not "default". The hint is in src/fields.ts, which all field commands use to find slice fields. The error class in src/lib stays free of CLI flag names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L1dGD8k3F268SphC2JdpP7
Resolves:
Description
Before this PR, the field commands could only change the primary fields of a slice. Slices upgraded with
prismic slice upgrade-legacykeep their repeatable fields in the deprecateditemszone, so users and agents could not view or edit those fields with the CLI.After this PR, slice field commands accept
--legacy-items-zoneto work on these fields, andprismic slice viewlists them. Without the flag, the commands work on the slice's fields as before. A variation that has no legacy items zone gives an error, so new slices keep using a repeatable Group.This is the CLI side of prismicio/editor#2652, which shows the same fields in the Type Builder.
Checklist
Preview
How to QA 1
Upgrade a legacy slice that has a repeatable zone. Run
prismic slice view <id>, then add, edit, and remove a field with--legacy-items-zone.Generated by Claude Code
Note
Medium Risk
Changes how slice model JSON is resolved and persisted across field CLI commands; mistakes could edit the wrong zone, though flags and errors constrain misuse.
Overview
Adds
--legacy-items-zoneto slice field commands so add, edit, remove, and reorder can target the deprecateditemszone on slices upgraded from the Legacy Builder, while default behavior still editsprimary.prismic slice viewnow prints a separate (legacy items zone) table when a variation hasitemsfields.field add grouprejects that flag with a clear error (repeatable groups belong on primary, not legacy items). Missing or empty legacy zones raiseSliceItemsNotFoundErrorwith hints to add a repeatable group instead.Core resolution lives in
resolveSliceFieldContainerand the sharedfieldshelpers; tests cover the new paths end to end.Reviewed by Cursor Bugbot for commit 48c9044. Bugbot is set up for automated code reviews on this repo. Configure here.
Generated by Claude Code
Footnotes
Please use these labels when submitting a review:
⚠️ #issue: Strongly suggest a change.
❓ #ask: Ask a question.
💡 #idea: Suggest an idea.
🎉 #nice: Share a compliment. ↩