symfony: [WebProfilerBundle] `/_wdt/styles.css` is not found

Symfony version(s) affected

7.2.0

Description

When I browse my local website, the debug toolbar is displayed without any style:

image

Loading http://localhost:8000/_wdt/styles.css in the browser shows:

The requested resource /_wdt/styles.css was not found on this server.

For some reason, it is passed to the PHP built-in server:

image

How to reproduce

The PHP server runs in Docker through php -S 0.0.0.0:8000 -t public/.

It looks like it’s not the source of the problem since http://localhost:8000/_wdt/50aa18?XDEBUG_IGNORE=1 works without any issue.

Possible Solution

See this workaround to change the path of the path in your project: https://github.com/symfony/symfony/issues/59045#issuecomment-2523839740

Additional Context

The debug toolbar has no issues:

image

Router

config/routes/web_profiler.yaml

when@dev:
    web_profiler_wdt:
        resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
        prefix: /_wdt

    web_profiler_profiler:
        resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
        prefix: /_profiler

debug:router:

$ bin/console debug:router _wdt_stylesheet
+--------------+--------------------------------------------------------------------------+
| Property     | Value                                                                    |
+--------------+--------------------------------------------------------------------------+
| Route Name   | _wdt_stylesheet                                                          |
| Path         | /_wdt/styles.css                                                         |
| Path Regex   | {^/_wdt/styles\.css$}sDu                                                 |
| Host         | ANY                                                                      |
| Host Regex   |                                                                          |
| Scheme       | ANY                                                                      |
| Method       | ANY                                                                      |
| Requirements | NO CUSTOM                                                                |
| Class        | Symfony\Component\Routing\Route                                          |
| Defaults     | _controller: web_profiler.controller.profiler::toolbarStylesheetAction() |
| Options      | compiler_class: Symfony\Component\Routing\RouteCompiler                  |
|              | utf8: true                                                               |
+--------------+--------------------------------------------------------------------------+

$ bin/console debug:router _wdt
+--------------+----------------------------------------------------------------+
| Property     | Value                                                          |
+--------------+----------------------------------------------------------------+
| Route Name   | _wdt                                                           |
| Path         | /_wdt/{token}                                                  |
| Path Regex   | {^/_wdt/(?P<token>[^/]++)$}sDu                                 |
| Host         | ANY                                                            |
| Host Regex   |                                                                |
| Scheme       | ANY                                                            |
| Method       | ANY                                                            |
| Requirements | NO CUSTOM                                                      |
| Class        | Symfony\Component\Routing\Route                                |
| Defaults     | _controller: web_profiler.controller.profiler::toolbarAction() |
| Options      | compiler_class: Symfony\Component\Routing\RouteCompiler        |
|              | utf8: true                                                     |
+--------------+----------------------------------------------------------------+

Related:

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 38 (22 by maintainers)

Commits related to this issue

Most upvoted comments

Got this issue too

Adding this to my NGiNX config seems to solve it, though I don’t really like having to configure something explicitly for a dev tool.

location ^~ /_wdt {
    try_files $uri /index.php?$query_string;
}

CSS is inlined on this page, it has no display issues:

My PR had a bad impact on you people and i’m sorry. Sincerely.

I’m trying to get all information i can, to find a good solution for everyone (for now: your suggestion to remove “.css” seems the best)

I’m not sure if that correspond to your question but the pro

On your first screenshot, we see the profiler token was 970bae (the 6 digits in the URL)

Can you try accessing to https://localhost:8000/_profiler/970bae/exception.css

Thanks

I reopen this issue so that Symfony’s maintainers can study this case.

Got this issue too

What server do you use? The built-in PHP server too?

I’m behind docker/nginx.

Thanks for your help 👍

Got this issue too

Here is a workaround by using the old version to override the new version:

  1. create the templates/bundles/WebProfilerBundle/Profiler/ directory
  2. copy-paste the old version of the Twig file in the toolbar_js.html.twig file in this new directory

Through CLI:

mkdir --parents templates/bundles/WebProfilerBundle/Profiler/
curl https://raw.githubusercontent.com/symfony/symfony/31b6a568850ad260b9d20122667a84ce0665ba7a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig \
--output templates/bundles/WebProfilerBundle/Profiler/toolbar_js.html.twig

This will revert this change and inline the CSS instead of loading it through an URL.

On this line: https://github.com/symfony/symfony/blob/4ed9d032c7b61ae49d526565bbc8fdbcf76d74c3/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/wdt.xml#L7

Replacing /styles.css with /styles fixes the issue: the CSS is rendered when calling /_wdt/styles.

So it looks like it’s a limitation of the built-in server of PHP. My hypothesis: it tries to find the file /_wdt/styles.css when this path is provided, but call Symfony when the path is changed to /_wdt/styles.

There is a PR opened that fixes this problem. Just have to wait for it to be merged.

https://github.com/symfony/symfony/pull/59229

On your first screenshot, we see the profiler token was 970bae (the 6 digits in the URL)

Can you try accessing to https://localhost:8000/_profiler/970bae/exception.css

Thanks

Here is the result:

image

What page load this CSS file? I never saw an issue with …/exception.css.

The solution that @alexislefebvre suggested is stable and clean, is agnostic to the webserver and doesn’t rely on editing vendor files

I was under the impression both the xml and the routing file needed to be changed. Read it wrong, thanks for clarifying.

The solution that @alexislefebvre suggested is stable and clean, is agnostic to the webserver and doesn’t rely on editing vendor files

I didn’t need to do any of that, only the wdt.xml file was enough, and clearing cache. Can you try it without that part ?

The wdt.xml is in the vendor/ directory so it only works on one install and can’t be deployed as is.

Solution by @alexislefebvre works perfectly for me

Another workaround:

On this line: https://github.com/symfony/symfony/blob/4ed9d032c7b61ae49d526565bbc8fdbcf76d74c3/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/wdt.xml#L7

Replacing /styles.css with /styles fixes the issue: the CSS is rendered when calling /_wdt/styles.

I was able to do this in a project:

config/routes/web_profiler.yaml

    when@dev:
        web_profiler_wdt:
            resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
            prefix: /_wdt
    
        web_profiler_profiler:
            resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
            prefix: /_profiler
    
+       _wdt_stylesheet:
+           path: /custom_wdt/styles
+           controller: web_profiler.controller.profiler::toolbarStylesheetAction

It may require to delete the cache.

Another workaround:

On this line:

https://github.com/symfony/symfony/blob/4ed9d032c7b61ae49d526565bbc8fdbcf76d74c3/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/wdt.xml#L7

Replacing /styles.css with /styles fixes the issue: the CSS is rendered when calling /_wdt/styles.

I was able to do this in a project, by changing the config instead of the file in vendor/:

config/routes/web_profiler.yaml

    when@dev:
        web_profiler_wdt:
            resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
            prefix: /_wdt
    
        web_profiler_profiler:
            resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
            prefix: /_profiler
    
+       _wdt_stylesheet:
+           path: /custom_wdt/styles
+           controller: web_profiler.controller.profiler::toolbarStylesheetAction

It may require to delete the cache.