Daily updates from Odoo
Thursday, May 16, 2024
1 change · saas-17.2
Resolved issues and error corrections
Fixes a web navigation issue where clicking links that point to a section on the same page could unexpectedly reload the app and send users back to the home menu. These links now behave as expected, improving reliability when navigating within pages.
Original PR description
When we changed client-side routing to be path based, we broke the behavior that allowed anchor-only links to scroll to the element with the corresponding id. It would instead cause the webclient to…
When we changed client-side routing to be path based, we broke the behavior that allowed anchor-only links to scroll to the element with the corresponding id. It would instead cause the webclient to attempt to load the state and end up on the home menu. This is caused by the fact that clicking on anchor links fires a popstate event, but that popstate event has no associated state. To fix this, we need to be able to differenciate a popstate event from an anchor click from other popstate events. Initially we considered simply setting a local variable when the user clicks on an anchor link, and checking that variable in the popstate handler, but this is both prone to race conditions and also causes issues when a link is clicked but preventDefault is called on the click event, preventing the popstate from occuring. As such, we decided instead to use the fact that the state on the popstate event from anchor clicks is null. The state is only null in two cases: when you click on such a link, or when you use the back button to go back to the first entry in history where the webclient was loaded. In the second case, this was purely incidental: we actually parsed the state from the URL and when the action mounted, it wouldn't touch the state because the new url was the same as the old one. In order to differenciate from the anchor link click, we now replace the state when the urls are identical. This will incidentally save us from parsing the url again if the user navigates back to this history entry, as the corresponding state will have been saved. Enterprise: https://github.com/odoo/enterprise/pull/60741