Problem Motivation

Back to site links to wrong path in case the last path visited in *Page not found* page.

Steps to reproduce

  1. Login as an admin
  2. Visit a page that does exist - for example the front page.
  3. Visit any page which does not exist: For example: http://example.com/not-found
    Not found
  4. Goto any page that exist, for example Modules page
    Modules
  5. Goto any other page that also exists, for example the config page
    Config
  6. Click *Back to site*. It links to 404 page in step 2, instead of page in step 5
    Error

Proposed resolution

Remaining Tasks

  • Write patch
  • Test, test and test

API Changes

None

CommentFileSizeAuthor
#63 interdiff_62-63.txt322 bytesraman.b
#63 2600652-63.patch12.49 KBraman.b
#62 interdiff_60-62.txt6.83 KBraman.b
#62 2600652-62.patch12.63 KBraman.b
#60 interdiff_58-60.txt818 bytessnehalgaikwad
#60 2600652-60.patch6.27 KBsnehalgaikwad
#58 interdiff_54-58.txt714 bytessnehalgaikwad
#58 2600652-58.patch6.19 KBsnehalgaikwad
#54 core-js-escapeAdmin-404-2600652-54.patch6.19 KBmrinalini9
#39 core-js-escapeAdmin-404-2600652-39.patch6.28 KBnod_
#30 not_found.png262.51 KBa_thakur
#29 modules.png254.82 KBa_thakur
#29 not found.png262.51 KBa_thakur
#29 config.png261.88 KBa_thakur
#15 back_to_site_links_to-2600652-15.patch2.49 KBcilefen
#15 interdiff.txt2.32 KBcilefen
#11 back-to-site-link-fix-2600652-11.patch2.28 KBa_thakur
#8 back-to-site-link-fix-2600652-8.patch2.47 KBa_thakur
#5 back-to-site-link-fix-2600652-5.patch717 bytesa_thakur
back_1.png64.92 KBa_thakur
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

a_thakur created an issue. See original summary.

dawehner’s picture

This is totally an interesting bug.

nod_’s picture

For resolution see what was done in the block overview page, there is no need to change the JS file, only adding a setting in drupalSettings is sufficient.

a_thakur’s picture

drupalSettings.path has currentPath variable which has value system/404, can we use this or is it better to add a new variable for this?

Object {baseUrl: "/", scriptPath: null, pathPrefix: "", currentPath: "system/404", currentPathIsAdmin: false…}baseUrl: "/"currentLanguage: "en"currentPath: "system/404"currentPathIsAdmin: falsecurrentQuery: ObjectisFront: falsepathPrefix: ""scriptPath: null__proto__: Object
a_thakur’s picture

Status: Needs work » Needs review
FileSize
717 bytes

Please find the attached patch which fixes the issue, instead of adding a new variable to drupalSettings.path for 404 pages, we can instead use currenPath instead which has value 'system/404' for page not found.

nod_’s picture

Status: Needs review » Needs work

As I said, no need to change the JS file, see what's done in Drupal\block\Controller::demo.


      '#attached' => array(
        'drupalSettings' => [
          // The block demonstration page is not marked as an administrative
          // page by \Drupal::service('router.admin_context')->isAdminRoute()
          // function in order to use the frontend theme. Since JavaScript
          // relies on a proper separation of admin pages, it needs to know this
          // is an actual administrative page.
          'path' => ['currentPathIsAdmin' => TRUE],
        ],

It's not strictly an admin page but sort of a "system" page. Either way, it'd solve the issue. If we start adding random stuff in the conditions we'll never see the end of it.

a_thakur’s picture

Thanks _nod for the review, will fix it as suggested.

a_thakur’s picture

Status: Needs work » Needs review
FileSize
2.47 KB

Changes made as suggested by nod_, there was also a typo in escapeAdmin.js file which I have fixed in this patch.

nod_’s picture

Status: Needs review » Needs work

leftover console.log

a_thakur’s picture

my bad..fixing it

a_thakur’s picture

Status: Needs work » Needs review
FileSize
2.28 KB

Removed console.log().

a_thakur’s picture

@nod_: could you please review?

Truptti’s picture

Verified the patch in #11 and it works fine.Steps performed to test the fix are as follows:
1.Applied the patch
2.Access the site and login as admin (Home page will be displayed http://localhost/drupal/user/1)
3.Navigate to "http://localhost/drupal/admin/config/trees", it will display "Page not found" error
4.Then click on link "Appearance" and then "Content"
5.Click on "Back to Site" link and the flow navigates to home page "http://localhost/drupal/user/1" instead of the error page "http://localhost/drupal/admin/config/trees"

This can be marked as RTBC.

nod_’s picture

The code is fine with me, the comment could be simplified a bit to be more accurate. Something along the lines of :
"Prevent the "back to site" functionality to save this page as the last non-admin page"

cilefen’s picture

sushantpaste’s picture

Status: Needs review » Reviewed & tested by the community

#15 works fine.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: back_to_site_links_to-2600652-15.patch, failed testing.

alexpott’s picture

Status: Needs work » Postponed
Issue tags: +Needs manual testing
Related issues: +#2595695: 4xx handling using subrequests: no longer able to vary by URL

I'm pretty sure this will turn out to be fixed by #2595695: 4xx handling using subrequests: no longer able to vary by URL if that patch addresses currentPath and currentPathIsAdmin in drupalSettings - which I think it should.

Wim Leers’s picture

Agreed; the patch here doesn't actually solve the problem. It merely treats the symptoms.

alexpott’s picture

I've just tried to reproduce this problem - I can't. Also it is a bit hard to see what the issue being reported is because the steps to reproduce in the issue summary aren;t complete. But I guess that the bask to site link contained system/404?

alexpott’s picture

Status: Postponed » Postponed (maintainer needs more info)

Changing to maintainer needs more info since I can't reproduce.

alexpott’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Needs work

Ah I see this is a somewhat different issue - the proper steps to reproduce are in #13. So I think the fix of marking system/403 and system/404 as admin paths is wrong and once #2595695: 4xx handling using subrequests: no longer able to vary by URL lands it would actually break this approach. I think the back to site storer should only store urls that are 2xx responses.

But also is this behaviour really incorrect? If a user goes to /new_page_i_want_to_create then uses the toolbar to create something that responses on this url wouldn't you want to be taken back to it?

alexpott’s picture

Well the node create example is a bad one because when you save the node you get taken to view the node in the site. But I've just manually tested the create view example and it totally works as designed for me.

Wim Leers’s picture

Status: Needs work » Closed (works as designed)

I think the back to site storer should only store urls that are 2xx responses.

+1

Wim Leers’s picture

Status: Closed (works as designed) » Needs work

Oops, obviously we can fix that here.

Wim Leers’s picture

Issue tags: +JavaScript

#2595695: 4xx handling using subrequests: no longer able to vary by URL was fixed. So let's do this.

Upon starting to do this, turns out that I think the back to site storer should only store urls that are 2xx responses. is impossible.

Hopefully @nod_ or @droplet has some idea.

Wim Leers’s picture

To clarify: JS cannot t get the response status AFAICT. Surprisingly.

a_thakur’s picture

Bumping into the issue after a long time..could not look into this earlier..agree with @Wim Leers that previous patch submitted only treats the symptoms..

a_thakur’s picture

Issue summary: View changes
FileSize
261.88 KB
262.51 KB
254.82 KB
a_thakur’s picture

FileSize
262.51 KB
a_thakur’s picture

Issue summary: View changes
a_thakur’s picture

Issue summary: View changes
a_thakur’s picture

Issue summary: View changes
a_thakur’s picture

Issue summary: View changes
a_thakur’s picture

Issue summary: View changes
a_thakur’s picture

Issue summary: View changes
a_thakur’s picture

Issue summary: View changes
subhojit777’s picture

+1

nod_’s picture

Changed the name from currentPathIsAdmin to escapeFromAdmin. As in "this page needs to show the escapeFromAdmin link". And whenever the link is shown, the script will not save the page as one to go back to.

As for saving only 2xx response, unless we add something to the markup or drupalSettings we can't do it as wim said.

Status: Needs review » Needs work

The last submitted patch, 39: core-js-escapeAdmin-404-2600652-39.patch, failed testing.

alexpott’s picture

Priority: Major » Normal

Discussed with @xjm, @catch, @cottser, and @effulgentsia. We agreed that this is not a major bug - the user is still on their site and whilst it probably makes sense to go back to the last 200 responses there are cases where this could be confusing. For example: you want to edit some block that is appearing on the 404 page and you click on the edit go into the admin screen makes some changes and then click back to site - if we implement this change you won't be going there.

droplet’s picture

Issue tags: +ux

It doesn't a bug IMO. ( but can be improve... )

tim.plunkett’s picture

Issue tags: -ux +Usability

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

nod_’s picture

Status: Needs work » Postponed (maintainer needs more info)

Need usability team feedback on #41.

It makes sense to me so I'd won't fix this issue.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

nod_’s picture

Version: 8.8.x-dev » 9.1.x-dev
Status: Postponed (maintainer needs more info) » Needs work
Issue tags: -JavaScript +JavaScript

Need reroll and feedback about usability on #41

mrinalini9’s picture

Assigned: Unassigned » mrinalini9
mrinalini9’s picture

Assigned: mrinalini9 » Unassigned
Status: Needs work » Needs review
FileSize
6.19 KB

Rerolled patch for 9.1.x, please review.

Status: Needs review » Needs work

The last submitted patch, 54: core-js-escapeAdmin-404-2600652-54.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

snehalgaikwad’s picture

Assigned: Unassigned » snehalgaikwad
pratik_kamble’s picture

Issue tags: +DIACWJuly2020
snehalgaikwad’s picture

Assigned: snehalgaikwad » Unassigned
Status: Needs work » Needs review
FileSize
6.19 KB
714 bytes

Status: Needs review » Needs work

The last submitted patch, 58: 2600652-58.patch, failed testing. View results

snehalgaikwad’s picture

Status: Needs work » Needs review
FileSize
6.27 KB
818 bytes

Status: Needs review » Needs work

The last submitted patch, 60: 2600652-60.patch, failed testing. View results

raman.b’s picture

Status: Needs work » Needs review
FileSize
12.63 KB
6.83 KB

Resolves the failed test cases in #60

raman.b’s picture

Removes the extra new line added in core/modules/toolbar/js/escapeAdmin.js

samiullah’s picture

Looks good

Applied patch #63
Steps to Test:
1.Login as an admin
2. Visit a page that does exist - for example the front page.
3. Visit any page which does not exist: For example: http://example.com/not-found
4. Visit any admin page example admin/modules
5. Visit other admin page example admin/config
6. Click on "Back to Site"

Expected: User should navigate back to frontpage

abhisekmazumdar’s picture

Status: Needs review » Reviewed & tested by the community

The patch #63 can be applied on 9.1.x. Also the patch resolves the 404 error page issue.
The patch looks good to me. Moving this to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/system/src/Controller/Http4xxController.php
    @@ -54,6 +54,12 @@ public function on403() {
    +      '#attached' => [
    +        'drupalSettings' => [
    +          // Do not save this page in as a non-admin page to go back to.
    +          'path' => ['escapeFromAdmin' => TRUE],
    +        ],
    +      ],
    

    Will this cause javascript to be loaded on a all 404 pages even if the user is anonymous?

  2. +++ b/core/modules/system/system.module
    @@ -712,7 +712,7 @@ function system_js_settings_alter(&$settings, AttachedAssetsInterface $assets) {
    -    'currentPathIsAdmin' => $current_path_is_admin,
    +    'escapeFromAdmin' => $current_path_is_admin,
    

    I don't think we should mix the name change with the fix. Also in the new world of deprecating things we need to support the old name until Drupal 10. This change is going to break contrib - http://grep.xnddx.ru/search?text=currentPathIsAdmin&filename=

  3. +++ b/core/modules/toolbar/js/escapeAdmin.es6.js
    @@ -13,7 +13,7 @@
    -    !pathInfo.currentPathIsAdmin &&
    +    !pathInfo.escapeFromAdmin &&
         !/destination=/.test(windowLocation.search)
       ) {
         sessionStorage.setItem('escapeAdminPath', windowLocation);
    @@ -35,7 +35,7 @@
    
    @@ -35,7 +35,7 @@
           const $toolbarEscape = $('[data-toolbar-escape-admin]').once(
             'escapeAdmin',
           );
    -      if ($toolbarEscape.length && pathInfo.currentPathIsAdmin) {
    +      if ($toolbarEscape.length && pathInfo.escapeFromAdmin) {
    

    Rather than changing the name can we change this logic to only store 2xx GET requests?

alexpott’s picture

Issue tags: +Needs tests

Also this can be tested with an automated test.

nod_’s picture

+1 to remove the rename, it's too late now.

To store only 2xx get request, we'll need to either add a meta with the HTTP response code the JS can use, or add a value in drupalSettings, which will trigger the loading of a little JS on all pages.

For the meta we should use <meta http-equiv="Status" content=""> https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta#attr-http... while status is not mentioned in the doc, it seems to have some use for indieweb webmentions: https://indieweb.org/meta_http-equiv_status so it could be useful to add anyway.

Probably should add the meta to everything except 2xx responses though.

alexpott’s picture

The <meta http-equiv="Status" content=""> idea is super interesting and worth exploring. I'm not sure about which way around this should be. One thought is that we add the setting only for logged in users atm and then proceed with the simple fix because logged in users will already have drupal settings.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.