Closed speller closed 1 year ago
:+1:
That isn't so much about EAB but Twig, or more so how your application uses it. EAB registers kernel.request
event (\EasyCorp\Bundle\EasyAdminBundle\EventListener\AdminRouterSubscriber::onKernelRequest
) and simply adds a global Twig variable. This can only happen before extensions and runtime are initialized (\Twig\ExtensionSet::initExtensions
). Something is triggering this before onKernelRequest
happens in your app, which means that EAB cannot add global variable. What's crucial, Twig will let you change the variable, despite the misleading addGlobal
prefix. However, adding new globals is impossible once the environment initializes.
From my experience this will cause problems with a lot of libraries, as adding Twig globals in onKernelRequest
is pretty standard. I would start from looking what causes the init in your case. As a dirty workaround you can initialize Twig global variable ea
with a null before the extension set is compiled. You can even do that with a custom twig extension or event listener... but this is a hack ;)
@speller thanks for reporting this, but I'm afraid we can't do anything on our side. We don't use RoadRunner and we don't have resources to try it or debug this.
Luckily, according to @kiler129 message, this could be not an issue with EasyAdmin itself but more related to Twig global variables. I hope you can find a solution, even if it's a bit hackish. Sorry!
@javiereguiluz probably EA shouldn't use twig globals to store context data
Related issue https://github.com/twigphp/Twig/issues/4007
I think we need to modify the way the global variable is declared. The Twig environment should not be initialized differently depending on the request.
The ea
variable can be replaced with a Twig function that would to the same as AdminContextProvider::getContext()
.
https://github.com/EasyCorp/EasyAdminBundle/blob/f63e526f65219f26a3add5020a6021a0f5e29e26/src/Provider/AdminContextProvider.php#L27
This function signature would require the current request from the global app
instead of dependency injection of RequestStack
:
# src/Resources/views/crud/field/array.html.twig
- {% if ea.crud.currentAction == 'detail' %}
+ {% if ea_context(app.request).crud.currentAction == 'detail' %}
@javiereguiluz Can you re-open this issue please.
Describe the bug
RoadRunner is a powerful replacement to the standard FPM which keeps PHP processes running. This makes PHP apps lightning-fast. The only drawback is that all PHP code must be stateless and not rely on global and static variables, all objects must be destroyed after the request. EasyAdmin seems to be not following these requirements and admin pages fail randomly with the following error:
To Reproduce Try using easyadmin under RR.
It would be nice if EA will fix this.