[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.
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
| setInputValue(value); | ||
| }, [value, setInputValue]); | ||
|
|
||
| const onChangeDebounced = _.debounce(onChange, 256); |
There was a problem hiding this comment.
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.
flash1293
left a comment
There was a problem hiding this comment.
Pushed the change from the comment and updated. Please check whether I haven't broke something else horribly, then this LGTM :)
wylieconlon
left a comment
There was a problem hiding this comment.
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.
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 OutStack TraceBuild 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
LayerInputcomponent 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