Repository navigation
Add segment mappers to translate content segment aliases - #1312
Merged
Merged
Conversation
Packages can register an ISyncSegmentMapper to turn site-specific segment aliases (e.g. ones named after database ids) into portable ones in uSync files, and back again on import. The content and media serializers use the new SyncSegmentMapperCollection, which is empty by default, so nothing changes unless a mapper is registered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 30, 2026
This was referenced Nov 30, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some packages name content segments after values that differ between sites. Umbraco Engage names each A/B test variant's segment
engage_ab-testing_{variantId}, where the id is a database id. uSync writes segment aliases to files as they are, so they point at the wrong variant on any other site.This adds an extension point so a package can translate those aliases when content is serialized and deserialized.
The interface
Register one in a composer:
The first mapper whose
IsMapperreturns true handles a segment. Blank segments never reach a mapper, and a mapper that returns a blank value keeps the original segment, so a segment value can't turn into the default value.Where it's used
ContentSerializerBase(content, media, blueprints):Segmentattribute on eachValueis mapped. The segments filter from options is still checked against the site alias, because the setting holds this site's aliases.Segmentattribute is mapped before the value is read from the item, compared and set. Value mappers get the site alias in both directions.Segmentsattribute on the root node. It holds the requested segment names from options, not stored values, and nothing reads it on import. The blank-value fill-in for missing cultures writes no segment, so it's untouched too.Reports compare the serialized XML of the current item with the file, so both sides go through the mapper and stay comparable. The content tracker works on the same XML.
Because this is in the serializer, uSync.Complete push and pull pick it up too.
Compatibility
The collection is empty by default and registered in
AdduSyncCore. With no mapper,GetExportSegmentAsync/GetImportSegmentAsyncreturn the input, so export files are byte-identical to before.ContentSerializerBase,ContentSerializer,MediaSerializerandContentTemplateSerializereach get a constructor that takesSyncSegmentMapperCollection. The existing constructors are marked[Obsolete](removal in v19) and passSyncSegmentMapperCollection.Empty.Tests
ContentSegmentMapperTestsregisters a fake mapper (test_1↔test_key) and checks export, import (including an unmapped segment and the default value) and a no-change report.SyncSegmentMapperCollectionTestscovers the empty collection, round trips, unhandled segments and blank results. Full suite: 386 passed.Found along the way (not changed here)
Property values are sorted by culture only, so values for different segments come out in whatever order the item holds them. An item that hasn't been reloaded since saving can list segments in a different order from the database, and two sites can hold them in different orders, which shows as a change in reports. Sorting by segment as well would fix that, but it changes the order in existing files, so it belongs in its own PR.
🤖 Generated with Claude Code