Closed yoann54 closed 1 month ago
hi @yoann54, thanks for your message could you detail your error. without a way to reproduce it, it's difficult to solve it. you don't even specify where the error comes from, where you implemented your twig functions. there is no code, no configuration Sorry but if you don't take the time to detail your problem, it won't make the repository maintainers want to take the time to help you.
Sorry i didn't explained the error quite well. In my case i had an error in a twig component so an error was throwed (error 500) so the template of the error page appear but without the style. It seems that the vite entry is not read at this point. I tried to change the vite entry css by a static link tag and it works in this case.
This happens when an error is thrown after vite_entry_link_tags
is called and the twig error template calls vite_entry_link_tags
again.
It happens because each rendered file is stored in the renderedFiles['styles']
array here:
So when vite_entry_link_tags
is called again, nothing is rendered because every file is now in the renderedFiles['styles']
array.
This is similar to the following webpack encore issue: https://github.com/symfony/webpack-encore-bundle/issues/73
I had the same issue on one of my projects with styled error pages and fixed it by creating the following event listener:
<?php
use Pentatrion\ViteBundle\Service\EntrypointRenderer;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
#[AsEventListener]
class ExceptionListener
{
public function __construct(private readonly EntrypointRenderer $entrypointRenderer)
{
}
public function __invoke(ExceptionEvent $event): void
{
if ($event->getThrowable() instanceof \Twig\Error\RuntimeError) {
$this->entrypointRenderer->reset();
}
}
}
I'm not sure whether this could (or should) be added at the bundle level as it seems a bit far reaching, but it does the job for now.
@andyexeter explained it so much better than me and as i said i did the same reset function.
thanks @andyexeter, I didn't understand. I've updated the doc if other people encounter the same issue : https://symfony-vite.pentatrion.com/guide/troubleshooting.html
vite-plugin-symfony version
6.5
vite-bundle version
6.5
your OS, node version, Symfony version, PHP version
symfony 6.3 php 8.2
Description
When an error occurs in my page (twig) a 500 is launched and the css on thie error template page is not loaded via the vite entry (it works if i write staticaly)
How to reproduce
Not easy to reproduce.
Possible Solution
it would be possible to do a reset when an error happens.