Render array only working with numeric keys I have a FieldFormatter that outputs a DIV, a table and attaches a JS library. 

Normally in Drupal (e.g. Form API) it's possible to label the render array keys however you like? Weirdly in this case, only numbering them seems to work.

If it's a typo, I'm not spotting it, and there are no errors in the log.

Are there differences in how FieldFormatter rendering works?

Working numeric keys:

  public function viewElements(FieldItemListInterface $items, $langcode) {

    // various logic ...

    $build = [];

    $build[0] = [
      // placeholder div for the YouTube player
      '#type' =&gt; 'container',
      '#attributes' =&gt; [
        'id' =&gt; ['youtube-timecode-player'],
      ],
    ];

    // various logic ...

    // attach our timecode.js javascript make the video ID available
    $build[0]['#attached']['library'][] = 'mymodule/youtube_timecode';
    $build[0]['#attached']['drupalSettings']['mymodule']['video_id'] = $video_id;

    $build[1] = [
      '#type' =&gt; 'table',
      '#caption' =&gt; $this-&gt;t('Questions'),
      '#header' =&gt; [$this-&gt;t('Time'), $this-&gt;t('Question')],
      '#rows' =&gt; $timecodes
    ];

    return $build;
  }


Non-working text keys (no output and no errors):

(I've changed 0 to video and 1 to timecode_list)

public function viewElements(FieldItemListInterface $items, $langcode) {

    // various logic ...

    $build = [];

    $build['video'] = [
        // placeholder div for the YouTube player
        '#type' =&gt; 'container',
        '#attributes' =&gt; [
            'id' =&gt; ['youtube-timecode-player'],
        ],
    ];

    // various logic ...

    // attach our timecode.js javascript make the video ID available
    $build['video']['#attached']['library'][] = 'mymodule/youtube_timecode';
    $build['video']['#attached']['drupalSettings']['mymodule']['video_id'] = $video_id;

    $build['timecode_list'] = [
        '#type' =&gt; 'table',
        '#caption' =&gt; $this-&gt;t('Questions'),
        '#header' =&gt; [$this-&gt;t('Time'), $this-&gt;t('Question')],
        '#rows' =&gt; $timecodes
    ];

    return $build;

}
The return value of FormatterInterface::viewElements is defined as:


  Return value
  
  array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.


The theming layer can't handle other arrays for field values, see  How to print all values of a multi-value field, except the first?