Update the `LayersIndex` class to ensure that layers that do not contain content are still written. Closes gh-20858