sonata-project / SonataPageBundle

This bundle provides a Site and Page management through container and block services
https://docs.sonata-project.org/projects/SonataPageBundle
MIT License
218 stars 209 forks source link

Web profiler not working after runtime added #1738

Closed haivala closed 11 months ago

haivala commented 11 months ago

as requested in #1727

your composer.json extra config (and what appear when you run composer dump-autoload)
index.php file
sonata_page.yaml config
  "extra": {
    "symfony-assets-install": "copy",
    "runtime": {
      "class": "Sonata\\PageBundle\\Runtime\\SonataPagePathRuntime"
    },
    "symfony": {
      "allow-contrib": true
    }
  }

index.php

<?php

use App\Kernel;

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
    return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};

sonata_page

sonata_page:
  multisite: host_with_path_by_locale
  use_streamed_response: true
  hide_disabled_blocks: true
  page_defaults:
    decorate: true
  skip_redirection: true
  router_auto_register:
    enabled: true
    priority: 200
  ignore_route_patterns:
    - ^(.*)admin(.*) # ignore admin route, ie route containing 'admin'
    - ^_(.*) # ignore symfony routes
  ignore_routes:
    - sonata_page_esi_cache
    - sonata_page_ssi_cache
    - sonata_page_js_sync_cache
    - sonata_page_js_async_cache
    - sonata_cache_apc
    - sonata_cache_esi
...
  ignore_uri_patterns:
    - ^/admin\/
    - ^/api\/
    - ^/stripe\/

  default_template: default
  templates:
    onecolumn:
...
  direct_publication: "%kernel.debug%"
# composer.phar dump-autoload                                                              
Generating autoload files
Generated autoload files
GeraudBourdin commented 11 months ago

Do we need siteRequest in subrequest process?

easy fix would be : Sonata\PageBundle\Site\HostPathByLocaleSiteSelector:28

    if($event->getRequestType() !== HttpKernelInterface::MAIN_REQUEST){
        return;
    }
eerison commented 11 months ago

SonataPagePathRuntime

why is it related with sub request 🤔 ?

eerison commented 11 months ago

as requested in #1727

your composer.json extra config (and what appear when you run composer dump-autoload)
index.php file
sonata_page.yaml config
  "extra": {
    "symfony-assets-install": "copy",
    "runtime": {
      "class": "Sonata\\PageBundle\\Runtime\\SonataPagePathRuntime"
    },
    "symfony": {
      "allow-contrib": true
    }
  }

index.php

<?php

use App\Kernel;

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
    return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};

sonata_page

sonata_page:
  multisite: host_with_path_by_locale
  use_streamed_response: true
  hide_disabled_blocks: true
  page_defaults:
    decorate: true
  skip_redirection: true
  router_auto_register:
    enabled: true
    priority: 200
  ignore_route_patterns:
    - ^(.*)admin(.*) # ignore admin route, ie route containing 'admin'
    - ^_(.*) # ignore symfony routes
  ignore_routes:
    - sonata_page_esi_cache
    - sonata_page_ssi_cache
    - sonata_page_js_sync_cache
    - sonata_page_js_async_cache
    - sonata_cache_apc
    - sonata_cache_esi
...
  ignore_uri_patterns:
    - ^/admin\/
    - ^/api\/
    - ^/stripe\/

  default_template: default
  templates:
    onecolumn:
...
  direct_publication: "%kernel.debug%"
# composer.phar dump-autoload                                                              
Generating autoload files
Generated autoload files

I couldn't reproduce this issue, for me it is working using host_with_path_by_locale and runtime 🤔

@haivala any url is working for you or just some specific ones?

GeraudBourdin commented 11 months ago

i got the error on a fresh new install. I fact this is the first time i see this as it was workging before on my side.

haivala commented 11 months ago

Everything is working except in dev the debug web_profiler route is not. like _profiler/d90e37

eerison commented 11 months ago

Everything is working except in dev the debug web_profiler route is not. like _profiler/d90e37

cool I could reproduce the issue ;)

eerison commented 11 months ago

interesting .... RequestFactory doesn't check ignore routers but it works 😄

haivala commented 11 months ago

There is these in the logs. looks like double check: Router Sonata\PageBundle\Route\CmsPageRouter was unable to generate route. Reason: 'Route 'Route '_profiler' not found' not found': The Sonata CmsPageRouter cannot find url

I used this code to access the profiler: https://github.com/sonata-project/SonataPageBundle/issues/1738#issuecomment-1846935841

eerison commented 11 months ago

There is these in the logs. looks like double check: Router Sonata\PageBundle\Route\CmsPageRouter was unable to generate route. Reason: 'Route 'Route '_profiler' not found' not found': The Sonata CmsPageRouter cannot find url

I used this code to access the profiler: #1738 (comment)

I saw that there is a pice of code doing a similar check 🤔 https://github.com/sonata-project/SonataPageBundle/blob/b17903ff6249cd406fc7dce1e4ea78a86a827bae/src/CmsManager/DecoratorStrategy.php#L37

GeraudBourdin commented 11 months ago

Sorry i had work to do. Imho the main problem is in /Data/Projets/SonataExtra/SonataExtra/vendor/symfony/http-kernel/Fragment/InlineFragmentRenderer.php:116

Request is passed, but is recreated ? i don't understand how this could have worked before.

GeraudBourdin commented 11 months ago

it appears that using RequestFactory fix the issue.

For example using : return new HttpKernelRunner($application, RequestFactory::createFromGlobals('host_with_path_by_locale')); in the runtime as the initial MR fix the problem.

I think we should revert this change and go back to the extra param ;( I do not know how users could use fragments as i ve nevers used this, but in that case, it should contains siteRequestInterface no ?

GeraudBourdin commented 11 months ago

@eerison could you try this on your side?

eerison commented 11 months ago

n the runtime as the initial MR fix the problem.

I do not know how users could use fragments as i ve nevers used this,

when someone face this issue, they gonna open a issue and we gonna understand how it works.

GeraudBourdin commented 11 months ago

i think we should go back to the RequestFactory::createFromGlobals in the runtime. So, nobody will have to open any issue on this subject ^^