Skip to content

Segments: Preserve segmented property values after save (closes #22166)#22173

Merged
nielslyngsoe merged 5 commits into
mainfrom
v17/bugfix/22166-segmented-property-values
Apr 24, 2026
Merged

Segments: Preserve segmented property values after save (closes #22166)#22173
nielslyngsoe merged 5 commits into
mainfrom
v17/bugfix/22166-segmented-property-values

Conversation

@AndyButland

@AndyButland AndyButland commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

Description

This PR addresses #22166 which describes a situation when a property varies by segment but not by culture on a document type that varies by both, segment-specific values are silently dropped after save-and-publish because the preset builder's variant options don't include segment-only (null culture + segment) combinations.

With the change in this PR, after _processIncomingData runs the preset builder, original server values not covered by variant options are now merged back, preventing data loss.

Root Cause

In content-detail-workspace-base.ts, _processIncomingData replaces data.values entirely with the output of the preset builder. The preset builder only produces values for variant options from #getFilteredVariantOptions. For a property with variesByCulture=false, variesBySegment=true, filtering removes all options with non-null culture (leaving only the invariant option), so all segment-specific values are dropped.

Fix

After the preset builder generates processedValues, merge them with the original data.values. This is done by keeping all processed values and then appending any server values that weren't already covered. Preset values take priority, and server values are only added when missing.

Testing

Prerequisites: Enable segments

  1. Implement ISegmentService returning at least two segments (e.g. "VIP members" with alias vip-members, "Recurring visitors" with alias recurring-visitors) — see kjac.dev/posts/umbraco-16-brings-back-segments for a walkthrough. Register with a composer.
Segment service implementation
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus;

namespace Umbraco.Cms.Web.UI.Custom.Segments;

public class MySegmentService : ISegmentService
{
    private readonly Segment[] _segments =
    [
        new Segment { Alias = "vip-members", Name = "VIP members" },
        new Segment { Alias = "recurring-visitors", Name = "Recurring visitors" }
    ];

    public Task<Attempt<PagedModel<Segment>?, SegmentOperationStatus>> GetPagedSegmentsAsync(int skip = 0, int take = 100)
        => Task.FromResult
        (
            Attempt.SucceedWithStatus<PagedModel<Segment>?, SegmentOperationStatus>
            (
                SegmentOperationStatus.Success,
                new PagedModel<Segment> { Total = _segments.Length, Items = _segments.Skip(skip).Take(take) }
            )
        );
}
Segments composer
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Services;

namespace Umbraco.Cms.Web.UI.Custom.Segments;

public class MySegmentComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        builder.Services.AddUnique<ISegmentService, MySegmentService>();
        builder.Services.Configure<SegmentSettings>(settings => settings.Enabled = true);
    }
}
  1. Install at least two languages (e.g. English and Dutch) under Settings > Languages

Setup: Create a document type and content

  1. Create a document type with Allow vary by culture and Allow segmentation both enabled
  2. Add a text property — on the property, enable Allow segmentation but leave Allow vary by culture OFF (this is the "shared by culture, varies by segment" scenario)
  3. Create a content node using this document type

Reproduce the bug (without fix)

  1. In the backoffice, select a segment from the segment picker for the content node
  2. Enter a value in the segmented text property
  3. Click Save and publish and publish all variants
  4. Expected (bug): After save, the segmented property value disappears — the field is empty
  5. Reload the page — the value is still gone from the UI, despite the API response containing the correct value

Verify the fix

  1. With this branch, repeat the previous steps
  2. Expected: The segmented property value is preserved and displayed correctly after save-and-publish
  3. Switch between segments and cultures — all values remain intact
  4. Reload the page — values persist correctly

Additional edge cases to verify

  • Property varies by both culture and segment — values preserved
  • Property varies by culture only (no segmentation) — values preserved
  • Invariant property (no culture, no segment variation) — values preserved
  • Create new content with preset/default values — defaults still applied correctly

Copilot AI review requested due to automatic review settings March 18, 2026 14:24
@AndyButland AndyButland changed the title Backoffice: Preserve segmented property values after save-and-publish (closes #22166) Segments: Preserve segmented property values after save-and-publish (closes #22166) Mar 18, 2026

Copilot AI 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.

Pull request overview

Updates the content detail workspace’s incoming-data processing to avoid dropping existing server-side property values for culture+segment combinations that aren’t included in the preset builder’s variant options.

Changes:

  • Merges processedValues with original data.values, preserving values not produced by the preset variant builder.
  • Ensures segment-specific values are retained even when variant options don’t cover all culture/segment combinations.

You can also share your feedback on Copilot code review. Take the survey.

@AndyButland AndyButland changed the title Segments: Preserve segmented property values after save-and-publish (closes #22166) Segments: Preserve segmented property values after save (closes #22166) Apr 23, 2026

@nielslyngsoe nielslyngsoe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Works as expected

@nielslyngsoe nielslyngsoe merged commit a056da9 into main Apr 24, 2026
32 checks passed
@nielslyngsoe nielslyngsoe deleted the v17/bugfix/22166-segmented-property-values branch April 24, 2026 21:24
AndyButland added a commit that referenced this pull request Apr 26, 2026
… (#22173)

* Preserve segment-specific property values after save and publish.

* Addressed feedback from code review.

* Moved fix to a projection in UmbPropertyValuePresetVariantBuilderController.

---------

Co-authored-by: Niels Lyngsø <nsl@umbraco.dk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants