-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Stack Monitoring] Ensure GlobalState class has it's destroy() method called on unmount #139908
Conversation
Pinging @elastic/infra-monitoring-ui (Team:Infra Monitoring UI) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this!
While investigating this here #139231 (comment), I also noticed that this component creates GlobalState
as a local variable during rendering instead of creating it once during mount:
kibana/x-pack/plugins/monitoring/public/application/contexts/global_state_context.tsx
Line 46 in 5bf5258
const state = new GlobalState(query, toasts, localState as { [key: string]: unknown }); |
I think this also could be a problem as this can be called multiple times, and we clean up only the last state when the component unmounts.
Should we put this state into useRef
? Or into the useState
?
Yeah, that's a good point. Technically this component should only mount and render once given the Provider hierarchy. But it is susceptible to a subtle change somewhere upstream causing re-renders. I've moved the instantiation into a I did also look at cleaning up |
x-pack/plugins/monitoring/public/application/contexts/global_state_context.tsx
Outdated
Show resolved
Hide resolved
…tate_context.tsx Co-authored-by: Anton Dosov <[email protected]>
…-ref HEAD~1..HEAD --fix'
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: cc @Kerry350 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
… called on unmount (elastic#139908) * Ensure GlobalState class has it's destroy() method called * Move GlobalState instantiation to useState Co-authored-by: Anton Dosov <[email protected]> (cherry picked from commit 875a624)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
… called on unmount (#139908) (#140133) * Ensure GlobalState class has it's destroy() method called * Move GlobalState instantiation to useState Co-authored-by: Anton Dosov <[email protected]> (cherry picked from commit 875a624) Co-authored-by: Kerry Gallagher <[email protected]>
Summary
This fixes #135136 (and other related problems, e.g. #139231 (comment)).
Whilst the
GlobalState
class (which syncs to the URL) had adestroy()
method, it wasn't being called. This is now called on unmount of the top-level<GlobalStateProvider />
.Testing
I was able to consistently replicate the bug by doing the following:
This should throw a routing error without this PR.