Change record status: 
Project: 
Introduced in branch: 
8.5.x
Introduced in version: 
8.5.0-alpha1
Description: 

The Container render element now supports the #optional property. It allows control on whether or not to render the element when it has no visible children.

Before:
Independent of whether or not the container had any visible elements, the markup for the container would be produced, resulting in empty div elements:

$form['my-empty-container'] = array(
  '#type' => 'container',
  '#attributes' => array(
   'class' => 'my-class',
  ),
  'child' => [],
);

Will produce this empty div: <div class="my-class"></div>

After:
The new #optional property defaults to FALSE, so if you do not specify this property, the same empty div will be produced. However, if you set #optional to TRUE:

$form['my-empty-container'] = array(
  '#type' => 'container',
  '#optional' => TRUE,
  '#attributes' => array(
   'class' => 'my-class',
  ),
  'child' => [],
);

No markup will be produced.

Impacts: 
Module developers
Themers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done