Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect URL redirection when using browser back button #613

Open
nicohery opened this issue Mar 25, 2024 · 5 comments
Open

Incorrect URL redirection when using browser back button #613

nicohery opened this issue Mar 25, 2024 · 5 comments
Labels
Bug Something isn't working Verified The issue has been reproduced

Comments

@nicohery
Copy link

nicohery commented Mar 25, 2024

Describe the bug:

Navigating back using the browser's "Back" button after changing the product sort order on a product list page redirects the user to an incorrect URL: /[object%20History]. This issue disrupts the user's browsing experience by not correctly returning them to the previous state.

Expected behavior:

Users should be redirected to the previous page with the initial state or sort order intact when using the browser's "Back" button. This behavior is expected to work seamlessly, similar to how it functions with the default PrestaShop theme.

Steps to reproduce the issue:

  1. Install the Hummingbird theme on PrestaShop.
  2. Navigate to a product list page.
  3. Change the sort order of the products (for example, from "Lowest Price" to "Highest Price").
  4. Use the browser's "Back" button to attempt to return to the previous sort order or page.
  5. Observe that the URL is redirected to an incorrect address (/[object%20History]), which results in a 404 page.
    Whatever the browser used.

PrestaShop version(s) where the bug happened:

8.1.5

PHP version(s) where the bug happened:

8.1

@nico-leb
Copy link

Hello everyone, same issue here with hummingbird, also with paginated parameters ( ?page=2) when using the Back button.
User is redirected to the previous page then instantly on a 404 page : myshop.fr/[object History]

@florine2623 florine2623 added the Verified The issue has been reproduced label Mar 29, 2024
@nicohery
Copy link
Author

nicohery commented Apr 2, 2024

I have identified the line of code that seems to cause the problem.
File /src/js/modules/facetedsearch/update.ts line 98

if ($(Theme.selectors.listing.list).length) {
    window.addEventListener('popstate', (e) => {
      const {state} = e;
      window.location.href = state && state.current_url ? state.current_url : history;
    });
  }

@chrisai-dev
Copy link
Contributor

chrisai-dev commented Apr 23, 2024

I have identified the line of code that seems to cause the problem. File /src/js/modules/facetedsearch/update.ts line 98

if ($(Theme.selectors.listing.list).length) {
    window.addEventListener('popstate', (e) => {
      const {state} = e;
      window.location.href = state && state.current_url ? state.current_url : history;
    });
  }

Could you add this line after window.location.href to force a refresh, and test?

window.location.reload();

Edit:
Without this popstate listener on back navigation the facet checkboxes selection state won't update based on the url change, that's why the window.location.href needs to be set, and force reloaded to avoid caching issues.

@sharkooon
Copy link
Contributor

Type 'History' is not assignable to type 'string'. So it can't be set on window.location.href. Thats why we got [object%20History]

why not using:

      if (state && state.current_url) {
        window.location.href = state.current_url;
      } else {
        window.history.back();
      }

@chrisai-dev
Copy link
Contributor

Type 'History' is not assignable to type 'string'. So it can't be set on window.location.href. Thats why we got [object%20History]

why not using:

      if (state && state.current_url) {
        window.location.href = state.current_url;
      } else {
        window.history.back();
      }

I've tested this with the following,

Homepage -> Category page -> Changed price filter -> Back button

This returned me back to the homepage.

@tblivet tblivet added Bug Something isn't working labels Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Verified The issue has been reproduced
Projects
None yet
Development

No branches or pull requests

6 participants