Workaround
This is a bug in the Experience Editor. You can work around this issue by changing the rendering in Presentation Details with the Change
button.
Root Cause
When you replace a rendering with a compatible rendering in the Experience Editor, a new unique ID is generated for the rendering. As Chris Auer mentioned, Sitecore's implementation of Dynamic Placeholders is based on the unique ID of the rendering containing the placeholder, so the new unique ID breaks your placeholders. The Change
button in Presentation Details does not generate new unique IDs, so does not have this issue.
Fix
To fix the Experience Editor, you just have to patch the ReplaceRendering
pipeline processor.
Pipeline Processor
using Sitecore.Data.Items;
using Sitecore.Layouts;
using Sitecore.Pipelines.ExecutePageEditorAction;
namespace YourAssembly.Pipelines.ExecutePageEditorAction
{
public class ReplaceRenderingWithDynamicPlaceholders : ReplaceRendering
{
protected override RenderingDefinition DoReplaceRendering(
RenderingDefinition sourceRendering,
Item targetRenderingItem,
DeviceDefinition device)
{
// Preserve the UID of the original rendering so that dynamic placeholders will continue to work
var rendering = base.DoReplaceRendering(sourceRendering, targetRenderingItem, device);
rendering.UniqueId = sourceRendering.UniqueId;
return rendering;
}
}
}
Config Patch
Make sure you replace YourAssembly
with the appropriate namespace and assembly name.
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<group groupName="ExperienceEditor" name="ExperienceEditor">
<pipelines>
<executePageEditorAction>
<processor type="YourAssembly.Pipelines.ExecutePageEditorAction.ReplaceRenderingWithDynamicPlaceholders, YourAssembly"
patch:instead="*[@type='Sitecore.Pipelines.ExecutePageEditorAction.ReplaceRendering, Sitecore.ExperienceEditor']" />
</executePageEditorAction>
</pipelines>
</group>
</pipelines>
</sitecore>
</configuration>