diff options
| author | Levi Siuzdak (sile) <sile@odoo.com> | 2025-01-22 13:24:26 +0000 |
|---|---|---|
| committer | Levi Siuzdak (sile) <sile@odoo.com> | 2025-02-07 15:28:29 +0000 |
| commit | 27a7a1bd84424237957ab4d88cf0238fd6c4fd6c (patch) | |
| tree | c5c95e87ba8eb8d1f32a92793cbacca8f108ad59 | |
| parent | fd5e49305b7f2dcdf05b16c28fab6469a079b604 (diff) | |
[FIX] website_sale: allow browser history navigation on product pages
Versions
--------
- saas-17.4+
Steps
-----
1. Go eCommerce products page;
2. click on a product;
3. use browser's "Go back" button to go back.
Issue
-----
There's no going back.
Cause
-----
Commit 2efaa12fdb17 modified the `_setUrlHash` method used to manage
product attributes. One of the changes it made is modified the current
URL using `window.location.hash` instead of `window.location.replace`.
While both methods can make identical changes to the URL, a key
side-effect of `Location:replace()` is that the URL being replaced
won't get saved in the session's `History`[^1].
As this method is called the moment the page loads, modifying the URL
via `location.hash` will store the initial product page URL without
attribute hashes in the session history. Then when trying to navigate
back, the method will be called again immediately to apply attribute
hashes, again modifying the session history, making it virtually
impossible to leave the page without clicking a new URL.
Solution
--------
Use `history.replaceState` to update the current state, and not create
any new entries.
opw-4416701
[^1]: https://developer.mozilla.org/en-US/docs/Web/API/Location/replace
closes odoo/odoo#196858
X-original-commit: 90a9bcf8bc853e26080c2c254224a7c74d088bfc
Signed-off-by: Levi Siuzdak <sile@odoo.com>
| -rw-r--r-- | addons/website_sale/static/src/js/website_sale.js | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index b0818eb3649..00d762503c8 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -186,7 +186,8 @@ export const WebsiteSale = publicWidget.Widget.extend(VariantMixin, cartHandlerM let attributeIds = []; inputs.forEach((element) => attributeIds.push(element.dataset.attributeValueId)); if (attributeIds.length > 0) { - window.location.hash = `attribute_values=${attributeIds.join(',')}`; + // Avoid adding new entries in session history by replacing the current one + history.replaceState(null, '', '#attribute_values=' + attributeIds.join(',')); } }, /** |
