-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Lens] fix dimension label performance issues #69978
Conversation
Pinging @elastic/kibana-app (Team:KibanaApp) |
<EuiFieldText | ||
compressed | ||
data-test-subj="indexPattern-label-edit" | ||
value={inputValue} |
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.
It seems like this is only updating the value of the actual input field if the user types something in it - props changes coming in after the component got rendered the first time will be ignored.
A useEffect
updating the local state when the global state management pushes an update down should work fine. This is a very similar case handling it the same way: https://github.com/elastic/kibana/pull/69672/files
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.
Done! Thanks!
setInputValue(value); | ||
}, [value, setInputValue]); | ||
|
||
const onChangeDebounced = _.debounce(onChange, 256); |
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.
This is on me - because of the useEffect
this breaks now because the debounced change from 256ms ago overwrites what the user has typed till then:
The fix is really easy though - this only happens because the calls are not actually debounced, they are just delayed by 256 ms. debounce
keeps internal state about a call already "in flight". As it is called in the component body here, there is a new internal state per typed key, so it's not actually debouncing
The fix for this is really simple:
const onChangeDebounced = useMemo(() => _.debounce(onChange, 256), [onChange]);
By memoizing the debounce call, it will hold the same internal state for each invocation, thus only firing the state update by the end of a series of keystrokes.
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.
Pushed the change from the comment and updated. Please check whether I haven't broke something else horribly, then this LGTM :)
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 bug, tested in FF and Chrome. Found one potential change, but I don't think it's a requirement- I didn't thoroughly test the behavior on leaving Lens.
setInputValue(value); | ||
}, [value, setInputValue]); | ||
|
||
const onChangeDebounced = useMemo(() => _.debounce(onChange, 256), [onChange]); |
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.
We have a hook you could replace this with called useDebounce
, via import { useDebounce } from 'react-use';
. The main difference is that that hook clears itself on unmount.
@elasticmachine merge upstream |
…n-label-perf-issues
💛 Build succeeded, but was flaky
Test FailuresKibana Pipeline / kibana-xpack-agent / X-Pack Detection Engine API Integration Tests.x-pack/test/detection_engine_api_integration/basic/tests/find_statuses·ts.detection engine api security and spaces enabled find_statuses "after each" hook for "should return a single rule status when a single rule is loaded from a find status with defaults added"Standard Out
Stack Trace
Build metrics
History
To update your PR or re-run it, just comment with: |
* master: (46 commits) [Visualize] Add missing advanced settings and custom label for pipeline aggs (elastic#69688) Use dynamic: false for config saved object mappings (elastic#70436) [Ingest Pipelines] Error messages (elastic#70167) [APM] Show transaction rate per minute on Observability Overview page (elastic#70336) Filter out error when calculating a label (elastic#69934) [Visualizations] Each visType returns its supported triggers (elastic#70177) [Telemetry] Report data shippers (elastic#64935) Reduce SavedObjects mappings for Application Usage (elastic#70475) [Lens] fix dimension label performance issues (elastic#69978) Skip failing endgame tests (elastic#70548) [SIEM] Reenabling Cypress tests (elastic#70397) [SIEM][Security Solution][Endpoint] Endpoint Artifact Manifest Management + Artifact Download and Distribution (elastic#67707) [Security] Adds field mapping support to rule creation (elastic#70288) SECURITY-ENDPOINT: add fields for events to metadata document (elastic#70491) Fixed assertion in hybrid index pattern test to iterate through indices (elastic#70130) [SIEM][Exceptions] - Exception builder component (elastic#67013) [Ingest Manager] Rename data sources to package configs (elastic#70259) skip suites blocking es snapshot promomotion (elastic#70532) [Metrics UI] Fix asynchronicity and error handling in Snapshot API (elastic#70503) fix export response (elastic#70473) ...
Summary
Fixes #69568
I've extracted a
LayerInput
component with internal state that only updates global state on debounce.On the long run and with our plans of top-down state management approach this could be fixed with 'selector-like' approach instead.
Checklist