Hi I've created a module with a controller but now i'm getting this message;
The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\Core\Cache\CacheableJsonResponse.
this is my code:
$cpdata=[];
$cpdata[]=[
'image'=>'image.png',
'title'=>'item01',
'price'=>'30',
];
$cache_options['#cache'] = [
'contexts' => ['url',],
'tags' => ['node_list:Content']
];
$response = new CacheableJsonResponse($cpdata);
$response->addCacheableDependency(CacheableMetadata::createFromRenderArray($cache_options));
return $response;
is some way to fix this issue? I appreciate your help
$cpdata
isn't considered a render array because it doesn't contain any #-property.