Skip to content

feat: let slice field commands target the items zone - #463

Merged
angeloashmore merged 6 commits into
mainfrom
angeloashmore/slice-items-zone
Nov 16, 2026
Merged

angeloashmore merged 6 commits into
mainfrom
angeloashmore/slice-items-zone

Conversation

@angeloashmore

@angeloashmore angeloashmore commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Resolves:

Description

Before this PR, the field commands could only change the primary fields of a slice. Slices upgraded with prismic slice upgrade-legacy keep their repeatable fields in the deprecated items zone, so users and agents could not view or edit those fields with the CLI.

After this PR, slice field commands accept --legacy-items-zone to work on these fields, and prismic slice view lists 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

  • If my changes require tests, I added them.
  • If my changes affect backward compatibility, it has been discussed.
  • If my changes require an update to the CONTRIBUTING.md guide, I updated it.

Preview

$ prismic field add text subtitle --to-slice hero --legacy-items-zone
Field added: subtitle
$ prismic field add text x --to-slice hero --variation alt --legacy-items-zone
Variation "alt" of slice "hero" has no legacy items zone. Add fields to the slice instead.

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-zone to slice field commands so add, edit, remove, and reorder can target the deprecated items zone on slices upgraded from the Legacy Builder, while default behavior still edits primary.

prismic slice view now prints a separate (legacy items zone) table when a variation has items fields. field add group rejects that flag with a clear error (repeatable groups belong on primary, not legacy items). Missing or empty legacy zones raise SliceItemsNotFoundError with hints to add a repeatable group instead.

Core resolution lives in resolveSliceFieldContainer and the shared fields helpers; 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

  1. Please use these labels when submitting a review:
    ❓ #ask: Ask a question.
    💡 #idea: Suggest an idea.
    ⚠️ #issue: Strongly suggest a change.
    🎉 #nice: Share a compliment. ↩

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 jomifepe 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.

LGTM! Left one suggestion 💡

Comment thread src/lib/prismic/models.ts
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);

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.

⚠️ Removing the last items field locks the zone, and the error points users to 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.

  1. 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.
  2. Reword the error so it doesn't send people to primary without 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 of src/lib.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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

claude and others added 3 commits November 11, 2026 01:03
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
@angeloashmore
angeloashmore merged commit ce68e95 into main Nov 16, 2026
15 checks passed
@angeloashmore
angeloashmore deleted the angeloashmore/slice-items-zone branch November 16, 2026 19:30
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.

3 participants