fix unnecessary re-render which causes performance issue#12028
Conversation
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
Description
Fixes chart re-rendering oscillation when switching chart types (e.g., line → bar) for queries with multiple numerical columns in the same axis type (e.g.,
| stats AVG(bytes) as avg_bytes, MAX(bytes) as max_bytes by span(timestamp, 1h)). The chart would flash continuously because the axes mapping alternated between two states (y/color fields swapping).Root cause: Two issues combined after #11975 moved AxesSelectPanel to persist across chart type changes:
setAxesMapping: getAxesMappingByRulereturns string values ("max_bytes") whileconvertMappingsToStringsreturns arrays (["max_bytes"]).isEqual("str", ["str"])is false, causing spuriousvisConfig$re-emissions.AxesSelectPanel: TheuseEffectthat syncs selections to the builder hadchartTypeandremainingMappingsin its dependency array, causing it to fire on chart type changes with a stalecurrentSelectionswhose key insertion order differed — feeding columns togetAxesMappingByRulein a different order and producing a swapped mapping.Issues Resolved
Screenshot
Testing the changes
Check List
yarn test:jestyarn test:jest_integration