Error with custom template preprocessing function

I have written a custom theme preprocessor that returns the following error:

User error: "attributes" is an invalid render array key in DrupalCoreRenderElement::children() (line 97 of core/lib/Drupal/Core/Render/Element.php)

I have looked at the documentation for the Drupal Element object, as well as the source code for the original method, and don’t understand what is causing the error. Oddly, the elements render properly (including the attributes). Can anyone help me understand why this function seems to work, yet throws this error?

The following is an example of the $item_attrs var passed to new Attribute()
array(2) { ["class"]=> string(34) "view-grid__item view-grid__item--0" ["style"]=> string(24) "width: 33.333333333333%;" }

And this is the custom function

function mytheme_preprocess_views_view_grid(&$variables) {
  $options = $variables['view']->style_plugin->options;
  $item_num = 0;
  $items = [];

  // Iterate over each rendered views result row.
  foreach ($variables['rows'] as $item) {
    // Add item attributes
    $item_attrs = [];
    $item_attrs['class'] = "view-grid__item view-grid__item--{$item_num}";
    if ($options['automatic_width']) {
      $item_attrs['style'] = 'width: ' . (100 / $options['columns']) . '%;';
    }
    $items[$item_num]['attributes'] = new Attribute($item_attrs);

    // Add item.content
    $items[$item_num]['content'] = $item;

    // Increase, decrease or reset appropriate integers.
    $item_num++;

    // trigger_error($item_num);
  }

  // Add items to the variables array.
  $variables['items'] = $items;
}

SOLUTION

the issue was with the template, not the preprocessor (despite what the stack trace seemed to think 😉

i had to render `.content` on each element item

<div{{ attributes.addClass(classes) }}>
  {% for item in items %}
    <div{{ item.attributes }}
      {{ item.content }}
    </div>
  {% endfor %}
</div>

vs how i was doing it with just

<div{{ attributes.addClass(classes) }}>
  {% for item in items %}
    <div{{ item.attributes }}
      {{ item }}
    </div>
  {% endfor %}
</div>
Drupal version: 


Source: https://www.drupal.org/taxonomy/term/3/feed