Sonata : how to create a 404 error template?

I can’t create working 404 custom error pages in a production environment, with Sonata 4.13 and Symfony 5.4.

The official Sonata documentation didn’t help me, so I followed the Symfony documentation. I created a file in /templates/bundles/TwigBundle/Exception/error404.html.twig with the following content:

{% extends '@SonataAdmin/standard_layout.html.twig' %}

{% block title %}
    Erreur 404
{% endblock %}

{% block sonata_admin_content %}
<div class="box box-primary">
    <div class="box-body">
        <h1>404 - Page introuvable</h1>
        <p>La page que vous recherchez n'existe pas.</p>
        <p>Vous pouvez <a href="{{ path('home') }}">revenir au Dashboard</a>.</p>
    </div>
</div>
{% endblock %}

This page displays correctly when I access localhost/_error/404, but the sidebar is empty. When I test on the production environment, the same thing happens.

On this 404 error page, I notice that I’m not logged in (my username is not displayed), unlike on the other pages. Maybe the problem is coming from here?

What am I missing?

enter image description here