Title says it all.

This is happening because My account points to /user, which performs a redirect to the currently logged in user's profile page. However, it does a redirect using Symfony's RedirectResponse, which is not aware of formats, it always returns a HTML response. But worse, its Location header (which matters most of all) points to a URL without setting the current _format/_wrapper_format query argument, so the result is:

  1. AJAX request to /user?_wrapper_format=drupal_refreshless
  2. Response with a Location: /user/1 (note the absence of the _wrapper_format query argument)
  3. Browser follows redirect, and receives a HTML response, which causes the JS to fail.

I wonder if there's a core issue for the lack of AJAX redirect support on the server side.

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Seems like the actual root cause here is that the UrlGenerator doesn't take the current format into account…

wim leers’s picture

Filed a core issue and patch: #2714275: Redirects performed while a wrapper format is active loses the wrapper format, hence breaking AJAX, Dialogs, RefreshLess.

However… this won't actually fix everything. Because RefreshLess also expects additional query strings to be preserved: refreshless_page_state, ajax_page_state, et cetera. Therefore, I'm not going to block this on that core issue, I'm just going to fix it in RefreshLess itself.

(This must be resolved by the module that provides the wrapper format, which in this case is RefreshLess.)

So, stay tuned for a patch.

wim leers’s picture

Assigned: Unassigned » wim leers
Status: Active » Needs review
StatusFileSize
new4.1 KB

This works :)

But… the URL stubbornly stays at the original target URL: /user, not /user/345345. And AFAICT we unfortunately have no way of detecting what the redirected XHR's URL is… :/

wim leers’s picture

The first work-around attempt: generate the absolute URL on the client side. This works mostly… except that it utterly fails as soon as it comes to path aliases… So, alas, not a viable option.

wim leers’s picture

Here's a second attempt, this one works!

wim leers’s picture

StatusFileSize
new6.57 KB

Now merging #6 with #4, for a complete solution.

  • Wim Leers committed 86848d9 on 8.x-1.x
    Issue #2704075 by Wim Leers: Clicking the "My account" main menu link...
wim leers’s picture

Priority: Major » Critical
Status: Needs review » Fixed
StatusFileSize
new529 bytes

A tiny docs change on commit.

Also, I think this is critical, because it's a very frequently used link, present by default in Drupal 8. Many people will report this over and over if we don't fix it.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.