What is an orphaned rendering in Sitecore? An orphaned rendering is simply a rendering with no parent. By default, Experience Editor allows you to delete any rendering on your page. I am currently experiencing orphaned renderings when I'm creating pages to demo and the client is experiencing this during content entry. For example, I will delete a placeholder that has multiple renderings within it and that then creates our orphaned renderings. Since those orphaned renderings have no placeholder, they will not appear to an end user.
At the same time, if you look at presentation details, you will see a list of unused renderings. I started noticing the deeper you get into content entry, especially with highly edited pages, that orphaned renderings began to pile up; this can slow page performance and cause clutter to a content author or even a developer. A proactive approach for handling this issue is to implement a simple popup within Experience Editor to block a rendering from being deleted if it has child renderings within.
We want to locate the “\sitecore\shell\Applications\PageModes\ChromeTypes\RenderingChromeType.js” file. The ‘deleteControl’ method is where we will make our updates and you can delete the inner contents of that method. Below, we create a new method to check if our current rendering has children. If it does, then we set our ‘allowDeletion’ variable to false which prompts our popup message. You may need to clear your browsers cache once you save this.
The above example is helpful for Sitecore Experience Editor, but if you find that you and/or your client are doing a lot of work within content editor, then you want to implement a new saveUI pipeline. A good example can be demonstrated in this blog written by Mike Tschida. I am currently implementing this pipeline since the client has begun content entry and needed a way to clean things up from testing.
Illustration by: Html Vectors by Vecteezy