php-translation / symfony-bundle

Symfony integration for Translations
MIT License
327 stars 94 forks source link

Symfony 6.4 ReferenceError: Sfjs is not defined #504

Closed byhaskell closed 6 months ago

byhaskell commented 6 months ago

Hello. Thank you for such a great bundle, I hope it will live on for 7.0 and more.

If you install Symfony 6.4 or upgrade to it, the following error will appear in the profiler when you try to edit the translation: ReferenceError: Sfjs is not defined

How to avoid it? I did research and know that Sfjs is initialized in web_toolbar (twig) and dumped in Symfony 6.4 - it is not called, although all settings for the toolbar are positive.

bocharsky-bw commented 6 months ago

So everything seems working but you just noticed that error in the console? I didn't double-check that, but sounds like we may use that Sfjs faster that it was loaded on the page, something to debug more deep I think

byhaskell commented 6 months ago

@bocharsky-bw Thank you for your attention to my question. Yes, I see this error in the browser console, because after I click the EDIT button, the preloader spins and nothing happens. I also think that the script is loaded first than necessary, but I have not yet understood how to influence this.

bocharsky-bw commented 6 months ago

If you want to give it a try to fix it - PR is warmly welcome!

byhaskell commented 6 months ago

@bocharsky-bw Thank you. I will try to figure out how to do it, I have no experience with this. I understand how to do PR, but I understand how comprehensively it is possible to locally test changes in bundles. If I figure it out, I'll try to help.

byhaskell commented 6 months ago

@bocharsky-bw Hello. I found the reason in vendor/symfony/http-kernel/Profiler/Profiler.php on line 143 (https://github.com/symfony/http-kernel/blob/df0c04b049ddeabb3705a1b6ce1a99fe83fdd670/Profiler/Profiler.php#L143) not is being checked. I didn't find how to turn it on, maybe you have ideas? The config is as follows:

#config/packages/web_profiler.yaml
when@dev:
    web_profiler:
        toolbar: true
        intercept_redirects: true

    framework:
        profiler:
            only_exceptions: false
            collect_serializer_data: true

when@test:
    web_profiler:
        toolbar: false
        intercept_redirects: false

    framework:
        profiler: { collect: false }

During the checks, I realized that there is no X-Debug-Token in vendor/symfony/web-profiler-bundle/EventListener/WebDebugToolbarListener.php, and after starting the search for why it is not there, I reached this moment. Thank you for your kind help.

bocharsky-bw commented 6 months ago

Hm, probably there's another config that overwrites it? I would recommend to leverage bin/console debug:config command to check the actual config Symfony app got. Also, are you sure you're in dev mode? Probably further debugging is needed, I see it should be enabled by default unless explicitly disabled (the value that goes in the constructor), or disable() is called for some reasons

byhaskell commented 6 months ago

I only have one configuration file and the command confirms it.


Current configuration for "WebProfilerBundle"
=============================================

web_profiler:
    toolbar: true
    intercept_redirects: true
    excluded_ajax_paths: '^/((index|app(_[\w]+)?)\.php/)?_wdt'

Unfortunately, it is not clear why.

byhaskell commented 6 months ago

Upgrading php-translation/symfony-bundle (0.12.8 => 0.14.3). https://github.com/php-translation/symfony-bundle/commit/722e61673af494824b585b32bc619200b28729e4 https://github.com/php-translation/symfony-bundle/pull/500

Sorry, I don't know how, but I had an old version. I accidentally went through the templates, then decided to check what's in github and saw a commit about changing js.