Skip to content

[7.x] [ML] Improvements for urlState hook. (#70576)#71156

Merged
walterra merged 2 commits intoelastic:7.xfrom
walterra:backport/7.x/pr-70576
Jul 9, 2020
Merged

[7.x] [ML] Improvements for urlState hook. (#70576)#71156
walterra merged 2 commits intoelastic:7.xfrom
walterra:backport/7.x/pr-70576

Conversation

@walterra
Copy link
Copy Markdown
Contributor

@walterra walterra commented Jul 8, 2020

Backports the following commits to 7.x:

Makes two improvements to the urlState hook (also known as appState in some places):

- There was always a risk to run into a race condition because setUrlState could refer to a stale version of the state to act upon, for example if two calls were done in parallel. This is now fixed by using a local state copy of what we get from useLocation(). This allows us to use the callback version of useState's set function so we can make sure we always modify the latest state.
- Calls to history.push() are now gated by a check if the change actually referred to the corresponding instance of urlState (either _g or _a), this should reduce the updates resulting re-renders.

The two changes should make the use of setUrlState more safe against the pitfalls (race conditions/stale updates/lots of rerenders) we previously faced.
@walterra walterra added the backport This PR is a backport of another PR label Jul 8, 2020
@walterra walterra self-assigned this Jul 8, 2020
@walterra walterra added the :ml label Jul 8, 2020
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/ml-ui (:ml)

@walterra
Copy link
Copy Markdown
Contributor Author

walterra commented Jul 9, 2020

@elasticmachine merge upstream

@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Build metrics

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@walterra walterra merged commit 7dad41b into elastic:7.x Jul 9, 2020
@walterra walterra deleted the backport/7.x/pr-70576 branch July 9, 2020 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR :ml

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants