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:
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:
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:
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)
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.
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)
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.cssThanks
I reopen this issue so that Symfony’s maintainers can study this case.
I’m behind docker/nginx.
Thanks for your help 👍
Here is a workaround by using the old version to override the new version:
templates/bundles/WebProfilerBundle/Profiler/directorytoolbar_js.html.twigfile in this new directoryThrough CLI:
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.csswith/stylesfixes 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.csswhen 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
Here is the result:
What page load this CSS file? I never saw an issue with
…/exception.css.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
The
wdt.xmlis in thevendor/directory so it only works on one install and can’t be deployed as is.Solution by @alexislefebvre works perfectly for me
Another workaround:
I was able to do this in a project, by changing the config instead of the file in
vendor/:config/routes/web_profiler.yamlIt may require to delete the cache.