Error message Le site Web a rencontré une erreur inattendue. Veuillez essayer de nouveau plus tard.<br><br><em class="placeholder">LogicException</em>: 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\rest\ResourceResponse. in <em class="placeholder">Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()</em> (line <em class="placeholder">154</em> of <em class="placeholder">core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php</em>). <pre class="backtrace">Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169) Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81) Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58) Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48) Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 191) Drupal\page_cache\StackMiddleware\PageCache->fetch(Object, 1, 1) (Line: 128) Drupal\page_cache\StackMiddleware\PageCache->lookup(Object, 1, 1) (Line: 82) Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 49) Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 50) Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23) Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718) Drupal\Core\DrupalKernel->handle(Object) (Line: 19) </pre>``` ## Solution When encountering the "leaked metadata" error in Drupal, it generally means that something in your code is triggering a render process before Drupal expects it to. This can result in inaccurate cache metadata being associated with the response. This error is especially common when working with custom controllers, blocks, or hooks in Drupal. Here's a step-by-step guide on how to diagnose and fix this: 1. **Isolate the Source of the Issue**: - The error message points towards a `ResourceResponse` being returned. This is commonly used with REST endpoints in Drupal. If you've recently added or modified a custom REST endpoint, that's likely the culprit. - Identify what routes or paths produce the error. This will help narrow down the problematic code. 2. **Review Custom Code**: - Look for any uses of the `#markup` render array key or any calls to functions/methods that would trigger rendering, such as `render()`, inside the controller or block that corresponds to the problematic route. - Ensure that you're not returning a rendered output from your controller. Instead, return render arrays and let Drupal handle the rendering at the appropriate time. 3. **Avoid Early Rendering**: - Instead of using `#markup`, consider using more structured render array components like `#theme`, `#type`, etc. - If you need to process some logic to produce the render array, do so without actually rendering the content. 4. **Check Cache Metadata**: - If you're setting cache metadata manually (e.g., cache tags, contexts, or max-age), make sure you're attaching it to the render array properly, and not rendering content beforehand. 5. **Use Render Context**: - If you absolutely need to render something early (though it's rare that you should), wrap the rendering code within a render context to prevent cache metadata leakage. ```php $render_context = new \Drupal\Core\Render\RenderContext(); $output = \Drupal::service('renderer')->executeInRenderContext($render_context, function() { // Your rendering logic here. }); ``` 6. **Enable Detailed Logging**: - In case you can't find the source of the problem, make sure that detailed logging is enabled. Check the recent log messages (`/admin/reports/dblog` on your Drupal site) for any related warnings or notices that might give more information. 7. **Debugging Tools**: - Using debugging tools like Xdebug in combination with an IDE can be very helpful. Place a breakpoint at the line mentioned in the error message (`core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php` line 154) and inspect the call stack to see where the early rendering is being triggered. 8. **Community Support**: - If you're still stuck after following these steps, consider seeking help from the Drupal community. Drupal's issue queues, forums, and community chat platforms like Drupal Slack can be very helpful. Remember, the key is to ensure that content isn't being rendered too early in the process. Always return render arrays from controllers and hooks, and let Drupal's rendering system take care of producing the final output.