Easyadminbundle: Any url returns easyadmin.css contents from cache

Created on 16 Mar 2016  路  11Comments  路  Source: EasyCorp/EasyAdminBundle

I'm running into really strange behaviour from EasyAdmin (version 1.11.7 and 1.11.8 tested).

I have setup the routing as follows:

easy_admin_bundle:
    resource: "@EasyAdminBundle/Controller/"
    type:     annotation
    prefix:   /admin

After clicking around some list pages from some entities and finally reloading a list page all is fine. When afterwards I open https:/// it returns the contents from /admin/_css/easyadmin.css. The same result whent going to https:///admin. In fact it doesn't matter what I type behind the domain it will always return the css.
Only when doing a hard refresh it is all normal again.

As you can see in the attached images it somehow loads the css from cache from whatever url.

easyadmin-css-cache
easyadmin-css-cache-contents

bug

Most helpful comment

An update about this: we're going to remove this route associated with this CSS. The CSS contents will be preprocessed during container compilation. This hopefully will solve all problems.

All 11 comments

Wow! That's what I call a hard-to-debug error :confused:

In case you haven't looked at how we render the CSS, I'll explain briefly:

  • We use a easyadmin.css.twig template to generate a dynamic CSS file.
  • The CSS is served through its own URL /admin/_css/easyadmin.css
  • We link to the CSS file by rendering its route from the layout.html.twig template: <link rel="stylesheet" href="{{ path('_easyadmin_render_css') }}">

Looking at your error:

  • Everything works when using HTTP
  • If you switch to HTTPS, any URL returns the rendered CSS contents
  • If you reload the browser, everything works as expected again

It looks like some cache is doing nasty things ... but I'm completely clueless about this error.

@dopee a friendly ping to ask you if you could get more information about the conditions that trigger this error or if you managed to solve it? Thanks!

I have exactly the same problem. I'll try to send all stack trace from debug before redirection.

In case it's useful, the latest 1.12.1 version of this bundle has just been released. If confirmed, I consider this bug critical, so I hope you can find some time to test that version or to provide more information to reproduce the issue. Thanks!

I don't have much time to test, but I'll try to update and check if the problem still persists.
Will get back to you.

I've run composer update and it installed version 1.12.2
I'm sorry to report that the problem still persists.
I do not have anything else to mention than stated in the first post.

In short the following will trigger it for certain in my case:

  • open /admin
  • click around some entity listings
  • go to an item's edit view
  • go back to listing
  • hit reload (not forced)
  • adjust the browser address to / and hit enter
  • CSS is served (from cache)

@dopee thanks for taking a look at this! Let's see if @davidpv can also provide us more information to reproduce this issue. Thanks!

I also had a problem with easyadmin.css. I don't think it was the same one, but maybe it can give some ideas about what could be happening.

The problem: I've created a login page which included the easyadmin.css. After a successful login, I was being redirected to /admin/_css/easyadmin.css instead of the page I tried to access before the login.

The solution: My access control rules were set to block anonymous access to everything under /admin (except to /admin/login). Since the easyadmin.css is also under /admin and it is a route in the application, it was getting blocked. So, when I tried to access a protected area, the following happened:

  • Access /admin
  • /admin is protected, redirect to /admin/login and store /admin as the target_path
  • While rendering the login page, the browser made a request to /admin/_css/easyadmin.css, which redirected to /admin and stored /admin/_css/easyadmin.css as the target_url (I didn't notice any styling problem caused by this redirect because I wasn't using any of the styles of the css file. I was just including it)

I don't think this is a bug with EasyAdmin. Just a special case that one have to keep in mind. Maybe it would be helpful to add a note about it to the documentation.

I've created my own workaround by extending the AdminController and altering app/config/router.yml

It seems ok now. Basically I disabled all clientside caching on easyadmin.css.
Is it possible to check test this and incorporate in the bundle?

`namespace AppBundle\Controller;

use JavierEguiluz\Bundle\EasyAdminBundle\Controller\AdminController as EasyAdminController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class AdminController extends EasyAdminController
{
/**
* It renders the main CSS applied to the backend design. This controller
* allows to generate dynamic CSS files that use variables without the need
* to set up a CSS preprocessing toolchain.
*
* @Route("/_css/easyadmin.css", name="_easyadmin_render_css")
*
* @return Response
*/
public function renderCssAction()
{
$config = $this->container->getParameter('easyadmin.config');

    $cssContent = $this->renderView('@EasyAdmin/css/easyadmin.css.twig', array(
        'brand_color' => $config['design']['brand_color'],
        'color_scheme' => $config['design']['color_scheme'],
    ));

    $response = Response::create($cssContent, 200, array('Content-Type' => 'text/css'))
        ->setPrivate()
        ->setSharedMaxAge(0)
        ->setMaxAge(0)
        ;
    $response->headers->addCacheControlDirective('must-revalidate', true);

    return $response;
}

}
`

router.yml
easy_admin_bundle: resource: "@AppBundle/Controller/AdminController.php" type: annotation prefix: /admin

An update about this: we're going to remove this route associated with this CSS. The CSS contents will be preprocessed during container compilation. This hopefully will solve all problems.

The new version of the bundle, 1.12.5, has just been published. The URL associated with the CSS file no longer exists, so this error should be fixed.

Was this page helpful?
0 / 5 - 0 ratings