Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
systemd/services: Fix event handler race leading to wrong page switch
Event handlers are all async. It sometimes happened that clicking on a unit in the list, or the test changing the URL to a particular unit, for attempting to open the details page. This triggered the `onOptionsChanged` handler, which would reset the path back to the list. With some added debug logging, the logs look like this: > ServicesPageBody render list for path [] > Clicked on service in list, going to condtest.service > cockpit.location.get; window.location.hash "#/?type=service" > cockpit.Location.go: changed window.location.hash to #/condtest.service?type=service -> wait: ph_collected_text_is("#statuses .status","Not runningAutomatically starts") > cockpit.location.get; window.location.hash "#/condtest.service?type=service" creating new last_loc > ServicesPageBody onOptionsChanged; cockpit.location {"url_root":"","path":["condtest.service"],"options":{"type":"service"},"href":"/condtest.service?type=service"} merged options {"type":"service"} calling go to services list; path prop [] ^ i.e. here the onOptionsChanged fired, and reset the path back to `[]`. We can't use `this.props.path` either, as that hasn't been updated yet. > cockpit.location.get; window.location.hash "#/condtest.service?type=service" unchanged last_loc > cockpit.Location.go: changed window.location.hash to #/?type=service > locationchanged {"type":"service"} > usePageLocation changed {"url_root":"","path":[],"options":{"type":"service"},"href":"/?type=service"} So the details page often was not actually opened. Fix that by not hardcoding the target path to `[]`, but using the current one instead. This allows event handlers to be delayed even until after a page change. Fixes cockpit-project#18443
- Loading branch information