monsieurbiz / SyliusRichEditorPlugin

This plugin add a rich editor on fields to be able to drag and drop elements and edit it.
MIT License
65 stars 37 forks source link

monsieurbiz_sylius_rich_editor_admin_modal_form route does not work #94

Closed DieterHolvoet closed 3 years ago

DieterHolvoet commented 3 years ago

When clicking the edit button of a text element, nothing happens. In background, the call to /monsieurbiz_sylius_rich_editor/modal/edit gives a 404:

No route found for "POST /admin/monsieurbiz_sylius_rich_editor/modal/edit" (from "https://[host]/admin/homepages/1/edit")

After some debugging, I discovered that the problem is fixed by removing the condition: "request.isXmlHttpRequest()" line from admin.yaml. Is there any reason to leave it there? Doesn't seem essential to me. The fact that you're relying on a certain header being set by the client also doesn't make it 100% reliable.

DieterHolvoet commented 3 years ago

I created a pull request for the 1.0 branch since i'm using the stable version, but if you want I can also make a pull request for the master branch.

maximehuran commented 3 years ago

Hi,

Thanks for your feedback, which Sylius version are you using ? I made a test in our application and everything works fine : https://recordit.co/yLXsvcYx2s

The request.isXmlHttpRequest() is a security to be sure the controller is called in AJAX. So we cannot remove it and it works as it.

maximehuran commented 3 years ago

Be sure you are using the v2.0 of our plugin. It is in RC state but we will release it in stable version soon.

composer require monsieurbiz/sylius-rich-editor-plugin="v2.0.0-RC.3"
DieterHolvoet commented 3 years ago

I'm using sylius/sylius v1.8.0 and symfony/routing v4.4.13. I just don't really understand what it's protecting against, isXmlHttpRequest checks whether a certain header is present, so this can easily be cheated.

I'll try out the V2.0 version and I'll let you know if I'm having the same problem.

DieterHolvoet commented 3 years ago

Just updated to V2, still having the same issue. I made a screen recording. I'll also make a pull request for the master branch.

jacquesbh commented 3 years ago

Hi!

For you, removing the XmlHttpRequest condition solves the issue? Could you provide the Request headers that are passed for those URLs that are in 404 please?

And also provides the headers that are shown by the symfony's debugger?

It should not differ.

DieterHolvoet commented 3 years ago

Request headers in Chrome Dev Tools:

:authority: local.winkel.scoutsengidsenvilvoorde.be
:method: POST
:path: /admin/monsieurbiz_richeditor/render_elements
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: en-GB,en;q=0.9,en-US;q=0.8,nl;q=0.7
cache-control: no-cache
content-length: 1510
content-type: multipart/form-data; boundary=----WebKitFormBoundary1HASBqKPcZZQF7UJ
cookie: APP_ADMIN_REMEMBER_ME=QXBwXEVudGl0eVxVc2VyXEFkbWluVXNlcjpaR2xsZEdWeUxtaHZiSFp2WlhSQWMyTnZkWFJ6Wlc1bmFXUnpaVzUyYVd4MmIyOXlaR1V1WW1VPToxNjM2NTgzOTQ5Ojk0NGIzNTM4OGRlNjhlMzM0YWNkNjNiNjlkN2M2NDUyMTg4NmE1ZGMzNWNkNzY2MWI1Yzk2NGM4ZTljMmFiZDU%3D; PHPSESSID=ll4tg6vpoagm3u1qub12tqi4ru
origin: https://local.winkel.scoutsengidsenvilvoorde.be
pragma: no-cache
referer: https://local.winkel.scoutsengidsenvilvoorde.be/admin/homepages/3/edit
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.193 Safari/537.36
x-requested-with: XMLHttpRequest

Request headers in Symfony Profiler: Screenshot 2020-11-18 at 09 55 07

DieterHolvoet commented 3 years ago

And yes, removing the XmlHttpRequest condition solves the issue.

DieterHolvoet commented 3 years ago

I did some debugging.

Looks like the route conditions are not evalutated on the full Request object. Instead, a Request object is made here based on the path info. This request does not contain the original headers (including the x-requested-with header), so the condition fails:

Screenshot 2020-11-18 at 11 12 32

TLDR: Symfony should be using RequestMatcherInterface (which matches a request based on the request object), but in my case it's using UrlMatcherInterface (which matches a request based on the path info and lacks all other information).

Could you check which classes are implementing RequestMatcherInterface::matchRequest? Maybe you're on a different Symfony version, or you have different packages installed.

Screenshot 2020-11-18 at 11 40 30

jacquesbh commented 3 years ago

Hum.

Does your store have more than one channel? It could explain the match on the URL on Sylius. Also we didn't test this edge case. If that's the case then it's a pretty good catch.

Let me know! Thanks!

Edit: I've tested the plugin with more than one Channel on Sylius and it works fine. I did the test on Symfony 4.4.16 and Sylius 1.8.4.

DieterHolvoet commented 3 years ago

Yeah, I'm pretty sure this is not an issue with Sylius. My guess is that you (indirectly) have some packages installed that make the Symfony routing work differently than me. That's why I want to repeat my last question: could you check in a project where this plugin is running without problems which classes are implementing Symfony\Component\HttpFoundation\RequestMatcherInterface::matchRequest?

maximehuran commented 3 years ago

I have the issue on a project.

To answer to @DieterHolvoet :

On a working project :

image

On a non working project :

image

I am trying to know why the YAML conditions is not passed.

If I remove the condition condition: "request.isXmlHttpRequest() inside the routing and inside the Controller I dump $request->isXmlHttpRequest() it is to true :

image
maximehuran commented 3 years ago

I have dumped the request and the backtrace in Symfony\Component\HttpFoundation\Request::isXmlHttpRequest

public function isXmlHttpRequest()
    {
        dump($this);
        dump(debug_backtrace(2));
        return 'XMLHttpRequest' == $this->headers->get('X-Requested-With');
    }

The method is called three time :

First call (Without the correct header so return false)

Symfony\Component\HttpFoundation\Request {#3798 ▼
  +attributes: Symfony\Component\HttpFoundation\ParameterBag {#3801 ▶}
  +request: Symfony\Component\HttpFoundation\ParameterBag {#3803 ▶}
  +query: Symfony\Component\HttpFoundation\ParameterBag {#3802 ▶}
  +server: Symfony\Component\HttpFoundation\ServerBag {#3106 ▶}
  +files: Symfony\Component\HttpFoundation\FileBag {#3800 ▶}
  +cookies: Symfony\Component\HttpFoundation\ParameterBag {#3799 ▶}
  +headers: Symfony\Component\HttpFoundation\HeaderBag {#3107 ▼
    #headers: array:6 [▼
      "host" => array:1 [▶]
      "user-agent" => array:1 [▶]
      "accept" => array:1 [▶]
      "accept-language" => array:1 [▶]
      "accept-charset" => array:1 [▶]
      "content-type" => array:1 [▶]
    ]
    #cacheControl: []
  }
  #content: null
  #languages: null
  #charsets: null
  #encodings: null
  #acceptableContentTypes: null
  #pathInfo: null
  #requestUri: null
  #baseUrl: null
  #basePath: null
  #method: null
  #format: null
  #session: null
  #locale: null
  #defaultLocale: "en"
  -preferredFormat: null
  -isHostValid: true
  -isForwardedValid: true
  pathInfo: "/admin/monsieurbiz_richeditor/render_elements"
  requestUri: "/admin/monsieurbiz_richeditor/render_elements"
  baseUrl: ""
  basePath: ""
  method: "POST"
  format: "html"
}

In Request.php line 1730:

array:15 [▼
  0 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/var/cache/dev/UrlMatcher.php"
    "line" => 1562
    "function" => "isXmlHttpRequest"
    "class" => "Symfony\Component\HttpFoundation\Request"
    "type" => "->"
  ]
  1 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/routing/Matcher/Dumper/CompiledUrlMatcherTrait.php"
    "line" => 91
    "function" => "{closure}"
    "class" => "Symfony\Component\Routing\Router"
    "type" => "::"
  ]
  2 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/routing/Matcher/Dumper/CompiledUrlMatcherTrait.php"
    "line" => 38
    "function" => "doMatch"
    "class" => "Symfony\Component\Routing\Matcher\CompiledUrlMatcher"
    "type" => "->"
  ]
  3 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/routing/Router.php"
    "line" => 260
    "function" => "match"
    "class" => "Symfony\Component\Routing\Matcher\CompiledUrlMatcher"
    "type" => "->"
  ]
  4 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/Router/LocaleStrippingRouter.php"
    "line" => 39
    "function" => "match"
    "class" => "Symfony\Component\Routing\Router"
    "type" => "->"
  ]
  5 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/http-kernel/EventListener/RouterListener.php"
    "line" => 114
    "function" => "match"
    "class" => "Sylius\Bundle\ShopBundle\Router\LocaleStrippingRouter"
    "type" => "->"
  ]
  6 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/event-dispatcher/Debug/WrappedListener.php"
    "line" => 126
    "function" => "onKernelRequest"
    "class" => "Symfony\Component\HttpKernel\EventListener\RouterListener"
    "type" => "->"
  ]
  7 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/event-dispatcher/EventDispatcher.php"
    "line" => 264
    "function" => "__invoke"
    "class" => "Symfony\Component\EventDispatcher\Debug\WrappedListener"
    "type" => "->"
  ]
  8 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/event-dispatcher/EventDispatcher.php"
    "line" => 239
    "function" => "doDispatch"
    "class" => "Symfony\Component\EventDispatcher\EventDispatcher"
    "type" => "->"
  ]
  9 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/event-dispatcher/EventDispatcher.php"
    "line" => 73
    "function" => "callListeners"
    "class" => "Symfony\Component\EventDispatcher\EventDispatcher"
    "type" => "->"
  ]
  10 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php"
    "line" => 168
    "function" => "dispatch"
    "class" => "Symfony\Component\EventDispatcher\EventDispatcher"
    "type" => "->"
  ]
  11 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/http-kernel/HttpKernel.php"
    "line" => 134
    "function" => "dispatch"
    "class" => "Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher"
    "type" => "->"
  ]
  12 => array:5 [▶]
  13 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/http-kernel/Kernel.php"
    "line" => 201
    "function" => "handle"
    "class" => "Symfony\Component\HttpKernel\HttpKernel"
    "type" => "->"
  ]
  14 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/public/index.php"
    "line" => 25
    "function" => "handle"
    "class" => "Symfony\Component\HttpKernel\Kernel"
    "type" => "->"
  ]
]

Second call (With correct header)

In Request.php line 1729:

Symfony\Component\HttpFoundation\Request {#18 ▼
  +attributes: Symfony\Component\HttpFoundation\ParameterBag {#21 ▶}
  +request: Symfony\Component\HttpFoundation\ParameterBag {#19 ▶}
  +query: Symfony\Component\HttpFoundation\ParameterBag {#20 ▶}
  +server: Symfony\Component\HttpFoundation\ServerBag {#24 ▶}
  +files: Symfony\Component\HttpFoundation\FileBag {#23 ▶}
  +cookies: Symfony\Component\HttpFoundation\ParameterBag {#22 ▶}
  +headers: Symfony\Component\HttpFoundation\HeaderBag {#25 ▼
    #headers: array:17 [▶]
    #cacheControl: array:1 [▶]
  }
  #content: ""
  #languages: null
  #charsets: null
  #encodings: null
  #acceptableContentTypes: array:1 [▶]
  #pathInfo: "/admin/monsieurbiz_richeditor/render_elements"
  #requestUri: "/admin/monsieurbiz_richeditor/render_elements"
  #baseUrl: ""
  #basePath: null
  #method: "POST"
  #format: null
  #session: Symfony\Component\HttpFoundation\Session\Session {#238 ▶}
  #locale: null
  #defaultLocale: "fr_FR"
  -preferredFormat: null
  -isHostValid: true
  -isForwardedValid: true
  basePath: ""
  format: "html"
}

In Request.php line 1730:

array:13 [▼
  0 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/http-kernel/DataCollector/DumpDataCollector.php"
    "line" => 115
    "function" => "isXmlHttpRequest"
    "class" => "Symfony\Component\HttpFoundation\Request"
    "type" => "->"
  ]
  1 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/http-kernel/Profiler/Profiler.php"
    "line" => 178
    "function" => "collect"
    "class" => "Symfony\Component\HttpKernel\DataCollector\DumpDataCollector"
    "type" => "->"
  ]
  2 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/http-kernel/EventListener/ProfilerListener.php"
    "line" => 90
    "function" => "collect"
    "class" => "Symfony\Component\HttpKernel\Profiler\Profiler"
    "type" => "->"
  ]
  3 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/event-dispatcher/Debug/WrappedListener.php"
    "line" => 126
    "function" => "onKernelResponse"
    "class" => "Symfony\Component\HttpKernel\EventListener\ProfilerListener"
    "type" => "->"
  ]
  4 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/event-dispatcher/EventDispatcher.php"
    "line" => 264
    "function" => "__invoke"
    "class" => "Symfony\Component\EventDispatcher\Debug\WrappedListener"
    "type" => "->"
  ]
  5 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/event-dispatcher/EventDispatcher.php"
    "line" => 239
    "function" => "doDispatch"
    "class" => "Symfony\Component\EventDispatcher\EventDispatcher"
    "type" => "->"
  ]
  6 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/event-dispatcher/EventDispatcher.php"
    "line" => 73
    "function" => "callListeners"
    "class" => "Symfony\Component\EventDispatcher\EventDispatcher"
    "type" => "->"
  ]
  7 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php"
    "line" => 168
    "function" => "dispatch"
    "class" => "Symfony\Component\EventDispatcher\EventDispatcher"
    "type" => "->"
  ]
  8 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/http-kernel/HttpKernel.php"
    "line" => 191
    "function" => "dispatch"
    "class" => "Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher"
    "type" => "->"
  ]
  9 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/http-kernel/HttpKernel.php"
    "line" => 245
    "function" => "filterResponse"
    "class" => "Symfony\Component\HttpKernel\HttpKernel"
    "type" => "->"
  ]
  10 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/http-kernel/HttpKernel.php"
    "line" => 91
    "function" => "handleThrowable"
    "class" => "Symfony\Component\HttpKernel\HttpKernel"
    "type" => "->"
  ]
  11 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/http-kernel/Kernel.php"
    "line" => 201
    "function" => "handle"
    "class" => "Symfony\Component\HttpKernel\HttpKernel"
    "type" => "->"
  ]
  12 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/public/index.php"
    "line" => 25
    "function" => "handle"
    "class" => "Symfony\Component\HttpKernel\Kernel"
    "type" => "->"
  ]
]

Third call (With correct header, seems to be for the toolbar ?)

In Request.php line 1729:

Symfony\Component\HttpFoundation\Request {#18 ▼
  +attributes: Symfony\Component\HttpFoundation\ParameterBag {#21 ▶}
  +request: Symfony\Component\HttpFoundation\ParameterBag {#19 ▶}
  +query: Symfony\Component\HttpFoundation\ParameterBag {#20 ▶}
  +server: Symfony\Component\HttpFoundation\ServerBag {#24 ▶}
  +files: Symfony\Component\HttpFoundation\FileBag {#23 ▶}
  +cookies: Symfony\Component\HttpFoundation\ParameterBag {#22 ▶}
  +headers: Symfony\Component\HttpFoundation\HeaderBag {#25 ▼
    #headers: array:17 [▼
      "pragma" => array:1 [▶]
      "user-agent" => array:1 [▶]
      "accept-encoding" => array:1 [▶]
      "content-type" => array:1 [▶]
      "content-length" => array:1 [▶]
      "referer" => array:1 [▶]
      "mod-rewrite" => array:1 [▶]
      "x-requested-with" => array:1 [▶]
      "dnt" => array:1 [▶]
      "origin" => array:1 [▶]
      "host" => array:1 [▶]
      "accept" => array:1 [▶]
      "cache-control" => array:1 [▶]
      "te" => array:1 [▶]
      "cookie" => array:1 [▶]
      "accept-language" => array:1 [▶]
      "x-php-ob-level" => array:1 [▶]
    ]
    #cacheControl: array:1 [▶]
  }
  #content: ""
  #languages: null
  #charsets: null
  #encodings: null
  #acceptableContentTypes: array:1 [▶]
  #pathInfo: "/admin/monsieurbiz_richeditor/render_elements"
  #requestUri: "/admin/monsieurbiz_richeditor/render_elements"
  #baseUrl: ""
  #basePath: null
  #method: "POST"
  #format: null
  #session: Symfony\Component\HttpFoundation\Session\Session {#238 ▶}
  #locale: null
  #defaultLocale: "fr_FR"
  -preferredFormat: null
  -isHostValid: true
  -isForwardedValid: true
  basePath: ""
  format: "html"
}

In Request.php line 1730:

array:11 [▼
  0 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/web-profiler-bundle/EventListener/WebDebugToolbarListener.php"
    "line" => 86
    "function" => "isXmlHttpRequest"
    "class" => "Symfony\Component\HttpFoundation\Request"
    "type" => "->"
  ]
  1 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/event-dispatcher/Debug/WrappedListener.php"
    "line" => 126
    "function" => "onKernelResponse"
    "class" => "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener"
    "type" => "->"
  ]
  2 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/event-dispatcher/EventDispatcher.php"
    "line" => 264
    "function" => "__invoke"
    "class" => "Symfony\Component\EventDispatcher\Debug\WrappedListener"
    "type" => "->"
  ]
  3 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/event-dispatcher/EventDispatcher.php"
    "line" => 239
    "function" => "doDispatch"
    "class" => "Symfony\Component\EventDispatcher\EventDispatcher"
    "type" => "->"
  ]
  4 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/event-dispatcher/EventDispatcher.php"
    "line" => 73
    "function" => "callListeners"
    "class" => "Symfony\Component\EventDispatcher\EventDispatcher"
    "type" => "->"
  ]
  5 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php"
    "line" => 168
    "function" => "dispatch"
    "class" => "Symfony\Component\EventDispatcher\EventDispatcher"
    "type" => "->"
  ]
  6 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/http-kernel/HttpKernel.php"
    "line" => 191
    "function" => "dispatch"
    "class" => "Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher"
    "type" => "->"
  ]
  7 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/http-kernel/HttpKernel.php"
    "line" => 245
    "function" => "filterResponse"
    "class" => "Symfony\Component\HttpKernel\HttpKernel"
    "type" => "->"
  ]
  8 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/http-kernel/HttpKernel.php"
    "line" => 91
    "function" => "handleThrowable"
    "class" => "Symfony\Component\HttpKernel\HttpKernel"
    "type" => "->"
  ]
  9 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/vendor/symfony/http-kernel/Kernel.php"
    "line" => 201
    "function" => "handle"
    "class" => "Symfony\Component\HttpKernel\HttpKernel"
    "type" => "->"
  ]
  10 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-website/apps/sylius/public/index.php"
    "line" => 25
    "function" => "handle"
    "class" => "Symfony\Component\HttpKernel\Kernel"
    "type" => "->"
  ]
]

Conclusion

I checked the UrlMatcher in var/cache/dev/UrlMatcher.php and saw :

static function ($condition, $context, $request) { // $checkCondition
        switch ($condition) {
            case 1: return $request->isXmlHttpRequest();
            case -2: return (1 == 0);
        }
    },

I checked with a working project and I have the same. If I change the case 1 with true it works. The the issue is at this moment.

maximehuran commented 3 years ago

On the working project I have all my parameters in header bag s that's why it works :

 In Request.php line 1741:

Symfony\Component\HttpFoundation\Request {#18 ▼
  +attributes: Symfony\Component\HttpFoundation\ParameterBag {#95 ▶}
  +request: Symfony\Component\HttpFoundation\ParameterBag {#101 ▶}
  +query: Symfony\Component\HttpFoundation\ParameterBag {#96 ▶}
  +server: Symfony\Component\HttpFoundation\ServerBag {#92 ▶}
  +files: Symfony\Component\HttpFoundation\FileBag {#93 ▶}
  +cookies: Symfony\Component\HttpFoundation\ParameterBag {#94 ▶}
  +headers: Symfony\Component\HttpFoundation\HeaderBag {#91 ▼
    #headers: array:16 [▼
      "cookie" => array:1 [▶]
      "accept-language" => array:1 [▶]
      "te" => array:1 [▶]
      "content-type" => array:1 [▶]
      "content-length" => array:1 [▶]
      "dnt" => array:1 [▶]
      "x-requested-with" => array:1 [▶]
      "user-agent" => array:1 [▶]
      "accept" => array:1 [▶]
      "accept-encoding" => array:1 [▶]
      "origin" => array:1 [▶]
      "cache-control" => array:1 [▶]
      "host" => array:1 [▶]
      "mod-rewrite" => array:1 [▶]
      "referer" => array:1 [▶]
      "x-php-ob-level" => array:1 [▶]
    ]
    #cacheControl: array:1 [▶]
  }
  #content: null
  #languages: null
  #charsets: null
  #encodings: null
  #acceptableContentTypes: null
  #pathInfo: "/my-admin-url/monsieurbiz_richeditor/render_elements"
  #requestUri: "/my-admin-url/monsieurbiz_richeditor/render_elements"
  #baseUrl: ""
  #basePath: null
  #method: "POST"
  #format: null
  #session: Closure() {#4205 ▶}
  #locale: null
  #defaultLocale: "fr"
  -preferredFormat: null
  -isHostValid: true
  -isForwardedValid: true
  basePath: ""
  format: "html"
}

In Request.php line 1742:

array:15 [▼
  0 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-working-website/apps/sylius/var/cache/dev/UrlMatcher.php"
    "line" => 1975
    "function" => "isXmlHttpRequest"
    "class" => "Symfony\Component\HttpFoundation\Request"
    "type" => "->"
  ]
  1 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-working-website/apps/sylius/vendor/symfony/routing/Matcher/Dumper/CompiledUrlMatcherTrait.php"
    "line" => 91
    "function" => "{closure}"
    "class" => "Symfony\Component\Routing\Router"
    "type" => "::"
  ]
  2 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-working-website/apps/sylius/vendor/symfony/routing/Matcher/Dumper/CompiledUrlMatcherTrait.php"
    "line" => 38
    "function" => "doMatch"
    "class" => "Symfony\Component\Routing\Matcher\CompiledUrlMatcher"
    "type" => "->"
  ]
  3 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-working-website/apps/sylius/vendor/symfony/routing/Matcher/UrlMatcher.php"
    "line" => 106
    "function" => "match"
    "class" => "Symfony\Component\Routing\Matcher\CompiledUrlMatcher"
    "type" => "->"
  ]
  4 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-working-website/apps/sylius/vendor/symfony/routing/Router.php"
    "line" => 274
    "function" => "matchRequest"
    "class" => "Symfony\Component\Routing\Matcher\UrlMatcher"
    "type" => "->"
  ]
  5 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-working-website/apps/sylius/vendor/symfony/http-kernel/EventListener/RouterListener.php"
    "line" => 112
    "function" => "matchRequest"
    "class" => "Symfony\Component\Routing\Router"
    "type" => "->"
  ]
  6 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-working-website/apps/sylius/vendor/symfony/event-dispatcher/Debug/WrappedListener.php"
    "line" => 126
    "function" => "onKernelRequest"
    "class" => "Symfony\Component\HttpKernel\EventListener\RouterListener"
    "type" => "->"
  ]
  7 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-working-website/apps/sylius/vendor/symfony/event-dispatcher/EventDispatcher.php"
    "line" => 264
    "function" => "__invoke"
    "class" => "Symfony\Component\EventDispatcher\Debug\WrappedListener"
    "type" => "->"
  ]
  8 => array:5 [▶]
  9 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-working-website/apps/sylius/vendor/symfony/event-dispatcher/EventDispatcher.php"
    "line" => 73
    "function" => "callListeners"
    "class" => "Symfony\Component\EventDispatcher\EventDispatcher"
    "type" => "->"
  ]
  10 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-working-website/apps/sylius/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php"
    "line" => 168
    "function" => "dispatch"
    "class" => "Symfony\Component\EventDispatcher\EventDispatcher"
    "type" => "->"
  ]
  11 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-working-website/apps/sylius/vendor/symfony/http-kernel/HttpKernel.php"
    "line" => 134
    "function" => "dispatch"
    "class" => "Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher"
    "type" => "->"
  ]
  12 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-working-website/apps/sylius/vendor/symfony/http-kernel/HttpKernel.php"
    "line" => 80
    "function" => "handleRaw"
    "class" => "Symfony\Component\HttpKernel\HttpKernel"
    "type" => "->"
  ]
  13 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-working-website/apps/sylius/vendor/symfony/http-kernel/Kernel.php"
    "line" => 201
    "function" => "handle"
    "class" => "Symfony\Component\HttpKernel\HttpKernel"
    "type" => "->"
  ]
  14 => array:5 [▼
    "file" => "/Users/mhuran/Sites/my-working-website/apps/sylius/public/index.php"
    "line" => 33
    "function" => "handle"
    "class" => "Symfony\Component\HttpKernel\Kernel"
    "type" => "->"
  ]
]
maximehuran commented 3 years ago

If I check the diff I can see the request does not have the same params

image

On the stacktrace I see a diff with the LocaleStrippingRouter

image
maximehuran commented 3 years ago

@DieterHolvoet did you removed the locale on your URLs ?

If I comment the locale_switcher line, the isXmlHttpRequest is correct

sylius_shop:
    product_grid:
        include_all_descendants: true
#    locale_switcher: storage

Regarding to the doc :

* If `sylius_shop.locale_switcher` is set to `storage`, `LocaleStrippingRouter` is loaded, which strips out `_locale` parameter
  from the URL if it's the same as the one already in the storage. In order to disable localized urls, follow this cookbook entry: https://docs.sylius.com/en/latest/cookbook/disabling-localised-urls.html

ping @pamil may have an idea ?