-
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
[Logs UI] Fix errors during navigation #78319
Conversation
fb64c7d
to
962c907
Compare
962c907
to
f3098a5
Compare
Pinging @elastic/logs-metrics-ui (Team:logs-metrics-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.
Fixes the issue 👍
Question on the implementation: Would it have been possible to handle this in useTrackedPromise
alone, rather than adding the isMounted
awareness and onReject
callbacks to all the individual hooks?
E.g. where we have:
if (onResolve) {
onResolve(value);
}
in useTrackedPromise
could that have been:
if (onResolve && !isMounted) {
onResolve(value);
}
? useTrackedPromise
is already "aware" of mounted vs unmounted for the useEffect
.
Anyway, just curious, as this way does mean we need to add extra bits when we use the hook, but if there's an explicit reason then ignore this 😄
@Kerry350 I've almost suggested this as well. It makes sense to do that if we assume the |
That's a good question. My reasoning to not handle it in Consider this example: function SomeComponent() {
const [_, createPromise] = useTrackedPromise({
createPromise: () => Promise.resolve(),
onResolve: () => { console.log("will I be called?") },
});
useLayoutEffect(() => { createPromise() });
return null;
}
If we call This was my reasoning for it, but maybe this will never be a problem. Right now we are not using
...and we might never will 🤷, but it felt more right to move the responsibility of checking for "mountedness" to the components themselves. |
@elasticmachine merge upstream |
Yeah, in terms of a perfect design and where responsibility should lie what you've done feels right. However, because of the reality of our use cases (which I think would be 90%+ of the time we want the mount awareness) it feels like a lot of extra code.
Could we try the opt-out option? If it's not ideal, or presents issues, it can be reverted and we can merge this solution. |
I'll give it a shot 👍 |
@elasticmachine merge upstream |
The new flag will determine if the callbacks will trigger or the errors will throw if the component using the hook is not mounted. By default they will only trigger if it is.
@elasticmachine merge upstream |
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.
LGTM 🎉 Thanks for taking the time to switch around the solutions, and sorry for the delay in re-review.
@elasticmachine merge upstream |
Thank you @Kerry350 🙇 |
💚 Build SucceededMetrics [docs]async chunk count
async chunks size
distributable file count
page load bundle size
History
To update your PR or re-run it, just comment with: |
* master: Added `defaultActionMessage` to index threshold alert UI type definition (elastic#80936) [ILM] Migrate Delete phase and name field to Form Lib (elastic#82834) skip flaky suite (elastic#57426) [Alerting] adds an Run When field in the alert flyout to assign the action to an Action Group (elastic#82472) [APM] Expose APM event client as part of plugin contract (elastic#82724) [Logs UI] Fix errors during navigation (elastic#78319) Enable send to background in TSVB (elastic#82835) SavedObjects search_dsl: add match_phrase_prefix clauses when using prefix search (elastic#82693) [Ingest Manager] Unify install* under installPackage (elastic#82916)
…e-details-overlay * 'master' of github.com:elastic/kibana: (201 commits) Added `defaultActionMessage` to index threshold alert UI type definition (elastic#80936) [ILM] Migrate Delete phase and name field to Form Lib (elastic#82834) skip flaky suite (elastic#57426) [Alerting] adds an Run When field in the alert flyout to assign the action to an Action Group (elastic#82472) [APM] Expose APM event client as part of plugin contract (elastic#82724) [Logs UI] Fix errors during navigation (elastic#78319) Enable send to background in TSVB (elastic#82835) SavedObjects search_dsl: add match_phrase_prefix clauses when using prefix search (elastic#82693) [Ingest Manager] Unify install* under installPackage (elastic#82916) [Fleet] Make stream id unique in agent policy (elastic#82447) skip flaky suite (elastic#82915) skip flaky suite (elastic#75794) Copy `dateAsStringRt` to observability plugin (elastic#82839) [Maps] rename connected_components/map folder to mb_map (elastic#82897) [Security Solution] Fix EventsViewer DnD cypress tests (elastic#82619) [Security Solution] Adds logging and performance fan out API for threat/Indicator matching (elastic#82546) Implemented Alerting health status pusher by using task manager and status pooler for Kibana status plugins 'kibanahost/api/status' (elastic#79056) [APM] Adds new configuration 'xpack.apm.maxServiceEnvironments' (elastic#82090) Move single use function in line (elastic#82885) [ML] Add unsigned_long support to data frame analytics and anomaly detection (elastic#82636) ...
Summary
Closes #69854.
Avoid setting state when the container hooks are not mounted.
React warns if a component tries to call
useState
ordispatch
after a hook has been unmounted. This might happen if the call to any of those methods happens as a result of an async operation finishing after a component has been unmounted.To solve this, we check if the component is mounted before trying to set the state or dispatch actions.
How to reproduce in
master
(and test for correctness in the branch)